-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (67 loc) · 3.16 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import elements_db_functions
import csv
from datetime import datetime
import subprocess
from dotenv import dotenv_values
def main():
creds = dotenv_values()
# 90 days
new_ninety_day_pub_records = elements_db_functions.get_new_lbl_pub_records(
creds, "lbl-new-pub-records-ninety-days.sql")
ninety_day_file = write_csv_file(new_ninety_day_pub_records, "LBL-90-Day-pub-records")
# 1 fiscal year
new_fiscal_year_pub_records = elements_db_functions.get_new_lbl_pub_records(
creds, "lbl-new-pub-records-one-fiscal-year.sql")
three_year_file = write_csv_file(new_fiscal_year_pub_records, "LBL-one-fiscal-year-pub-records")
# New 90-day pubs with preprint files available
new_pubs_with_preprints = elements_db_functions.get_new_lbl_pub_records(
creds, "lbl-new-pubs-with-preprint-files-available.sql")
with_preprint_file = write_csv_file(new_pubs_with_preprints, "LBL-90-day-pubs-with-preprint-files")
# Embargoed pubs pubs
new_embargoed_pubs = elements_db_functions.get_new_lbl_pub_records(
creds, "lbl-embargoed-pubs.sql")
embargoed_file = write_csv_file(new_embargoed_pubs, "lbl-embargoed-pubs")
# Set up the mail process with attachment and email recipients
subprocess_setup = ['mail',
'-s', 'New LBL pub records without eSchol deposits',
'-a', ninety_day_file,
'-a', three_year_file,
'-a', with_preprint_file,
'-a', embargoed_file]
subprocess_setup += [creds['DEVIN'], creds['GEOFF'], creds['ALAINNA']]
# Text in the email body
input_byte_string = b'''The attached CSV files show:
LBL-90-Day-pub-records:
- Pubs without eScholarship records having an associated file deposit.
- eSchol OA location URLS are listed where present.
- with EuroPMC or arXive publication records
- with a Publication "Reporting Date 1" from the past 90 days.
- The sheet is ordered by "most likely candidates" first:
- Pub type Journal Article > Preprint
- Claimed authors > Pending authors
LBL-one-fiscal-year-pub-records:
- Same as above, but without the 90-day cutoff.
- Records are pulled from the start of the previous fiscal year.
LBL-90-day-pubs-with-preprint-files:
- New LBL publications
- Created in the past 90 days
- Without file deposits (OA Locations are noted when available)
- And have a related "preprint" publication with a file.
LBL-embargoed-pubs:
- Any pubs claimed by an LBL author with an embargo date after "now."
- Funding info included where available.
'''
# Run the subprocess with EOT input to send
subprocess.run(subprocess_setup, input=input_byte_string, capture_output=True)
# Writes the CSV and returns the filename for email attachment
def write_csv_file(data, filename):
filename_with_date = "output/" + filename + "-" + datetime.today().strftime('%Y-%m-%d') + ".csv"
with open(filename_with_date, "w") as outfile:
csv_writer = csv.writer(outfile)
csv_writer.writerow(data[0].keys())
for row in data:
csv_writer.writerow(row.values())
return filename_with_date
# Stub for main
if __name__ == '__main__':
main()