-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·71 lines (59 loc) · 2.64 KB
/
main.py
File metadata and controls
executable file
·71 lines (59 loc) · 2.64 KB
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
#!/usr/bin/env python3
import os
import sys
from simple_term_menu import TerminalMenu
from client import Client
from descriptions import DescriptionLoader
from events import NewEventInfo
from lang import Lang
from utils import previous_weekday
from devices import setDevices
from dotenv import load_dotenv
load_dotenv()
def main():
organizer = os.environ.get('ORGANIZER', 'dojosw')
client = Client.from_env(organizer, default_lang=Lang.DE, read_only=False)
events = client.get_events()
last_n_events = events[-10:][::-1]
options = ['{} {}'.format(e.date_from.strftime("%a. %d.%m.%Y, %H:%M Uhr"), e.slug) for e in last_n_events]
options.append('[c] cancel')
menu = TerminalMenu(options, title='Choose template event')
entry_select = menu.show()
if entry_select == len(options) - 1:
print('cancelled')
return
template_event = last_n_events[entry_select]
# ask new data from user
info = NewEventInfo.from_user_input(template_event.name)
new_event = client.clone_event(info, template_event)
# change description
description_loader = DescriptionLoader.from_dir()
options = list(description_loader.descriptions.keys())
options.append('[c] cancel')
menu = TerminalMenu(options, title='Choose description')
entry_select = menu.show()
if entry_select == len(options) - 1:
print('cancelled')
return
description = description_loader.descriptions[options[entry_select]]
# add needed devices for workshop to description
options = ["Laptop", "Tablet", "Smartphone"]
menu = TerminalMenu(options, title='What devices should be brought?\nInfo: Press Enter without selecting for no additional devices-text\n * Select with space', multi_select=True, multi_select_empty_ok=True)
entry_select = menu.show()
if entry_select == len(options) - 1:
print('cancelled')
return
updatedDesc = setDevices(menu.chosen_menu_entries, description)
client.patch_event_settings(new_event, {'frontpage_text': updatedDesc})
# change available date from latecomer tickets
try:
products = client.get_event_products(new_event)
latecomer_ticket = next(p for p in products if 'atecomer' in p.get_name(Lang.EN))
wednesday_before = previous_weekday(info.date_from, 2)
wednesday_before = wednesday_before.replace(hour=1) # at 1 am
client.patch_product(new_event, latecomer_ticket, {'available_from': wednesday_before.isoformat()})
except StopIteration:
# if no latecomer ticket is available
print("No latecomer ticket found. Failed to set availabilty date", file=sys.stderr)
if __name__ == '__main__':
main()