forked from EuroPython/ep-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
154 lines (122 loc) · 5.22 KB
/
tasks.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""
Invoke tasks to be run from the command line.
"""
import os.path as op
from invoke import task
from eptools.server_utils import epcon_fetch_p3db
from eptools.gspread_utils import get_api_key_file
from eptools.talks import check_schedule
from eptools.talks import fetch_talks_json as _fetch_talks
from eptools.people import fetch_ticket_profiles as _fetch_profiles
from eptools.config import (sponsors_billing_worksheet,
finaid_submissions_worksheet,
)
@task
def sponsor_agreement(ctx, company_name, output_dir,
template_file='',
api_key_file=''):
""" Call docstamp to produce a sponsor agreement for `company_name`
using `template_file`. The output will be saved in `output_dir`.
Parameters
----------
company_name: str
Can be a substring of the company name in the spreadsheet.
template_file: str
output_dir: str
api_key_file: str
The path to the Google Credentials json file.
If left empty will try to look for its path in the config.py file.
"""
from eptools.sponsors import (get_sponsor,
get_sponsors_ws_data,
create_sponsor_agreement,
contract_template,
)
if not template_file:
template_file = contract_template
if not api_key_file:
api_key_file = get_api_key_file()
output_dir = op.abspath(output_dir)
responses = get_sponsors_ws_data(api_key_file=api_key_file,
doc_key=sponsors_billing_worksheet[0])
try:
sponsor_data = get_sponsor(sponsor_name=company_name,
sponsors=responses,
col_name='company')
except:
raise KeyError('Could not find data for sponsor {}.'.format(company_name))
else:
fpath = create_sponsor_agreement(sponsor_data,
template_file=template_file,
field_name='company',
output_dir=output_dir)
print('Created {}.'.format(fpath))
@task
def finaid_receipt(cts, applicant_name, output_dir,
template_file='',
api_key_file=''):
""" Call docstamp to produce a financial aid receipt
for `applicant_name` using `template_file`.
The output will be saved in `output_dir`.
Parameters
----------
applicant_name: str
template_file: str
output_dir: str
api_key_file: str
Path to the Google credentials json file.
If left empty will try to look for its path in the config.py file.
"""
from eptools.finaid import (get_finaid_ws_data,
get_applicant,
receipt_template_spa,
create_receipt,
)
if not template_file:
template_file = receipt_template_spa
if not api_key_file:
api_key_file = get_api_key_file()
output_dir = op.abspath(output_dir)
responses = get_finaid_ws_data(api_key_file=api_key_file,
doc_key=finaid_submissions_worksheet[0])
try:
applicant_data = get_applicant(applicant_name=applicant_name,
submissions=responses,
col_name='full_name')
except:
raise KeyError('Could not find data for applicant {}.'.format(applicant_name))
else:
fpath = create_receipt(applicant_data,
template_file=template_file,
output_dir=output_dir)
print('Created {}.'.format(fpath))
@task
def fetch_ticket_profiles(ctx, out_filepath, conf='ep2017', status='all',
nondups=False, raise_=False, ticket_id=''):
""" Create a json file with the all the tickets of the conference.
make_option('--status',
choices=['all', 'complete', 'incomplete'],
help='Status of the orders related with the tickets.',
make_option('--nondups',
help='If enables will remove the tickets with '
'same owner/email.',
make_option('--raise',
help='If enabled will raise any error that it may find.',
make_option('--ticket-id',
help='Will output the profile of the given ticket only.',
"""
return _fetch_profiles(out_filepath, conf=conf, status=status,
nondups=nondups, raise_=raise_, ticket_id=ticket_id)
@task
def fetch_talks_json(ctx, out_filepath='',
status='proposed',
conf='ep2017',
host='europython.io',
with_votes=False):
""" Return the talks in a json format. `status` choices: ['accepted', 'proposed']
"""
return _fetch_talks(out_filepath=out_filepath,
status=status,
conf=conf,
host=host,
with_votes=with_votes)