-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexports.py
139 lines (92 loc) · 5.24 KB
/
exports.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
import sys
import datetime
import os.path
import pandas as pd
from ics import Calendar, Event
def export_upcoming_shows(df_shows, df_venues, workdir_path, ui):
print("Export upcoming shows:")
df_coming_shows = df_shows.loc[df_shows['Status'] == 0]
print(df_coming_shows)
# create title
output = "UPCOMING SHOWS (" + f"{datetime.datetime.now():%Y-%m-%d}" + ")<br/>"
# iterate through shows_df and concat venue_df, then append text to output
for i, row in df_coming_shows.iterrows():
if row["VenueID"] in df_venues.index:
venue = df_venues.loc[row["VenueID"]]
df_out = pd.concat([row, venue])
output += "<br/>" + df_out.to_markdown(index=True, tablefmt="html") + "<br/>" # also possible: .to_string(index=True)
# output += "<br/>" + df_out.to_frame().to_html() + "<br/>"
# write output to text file
export_path = os.path.join(workdir_path, "UpcomingShows.html")
with open(export_path, 'w') as file:
file.write(output)
ui.statusbar.showMessage("Upcoming Shows exported to HTML-file!", 3000)
def export_all_calendars(df_shows, df_venues, workdir_path, ui, show_status_list):
export_show_calendar(df_shows, workdir_path, show_status_list)
export_event_calendar(df_venues, workdir_path)
export_event_forcast_calendar(df_venues, workdir_path)
ui.statusbar.showMessage("Show Calendar and Event Calendar exported to ICS-files!", 3000)
def export_show_calendar(df_shows, workdir_path, show_status_list): # SHOWS
print("export show calendar")
# to subscribe in thunderbird (Add Network Calendar) with url:
# file:///path/to/your/workdir/TourManagerShows.ics
c = Calendar()
for i, row in df_shows.iterrows():
if row["Status"] != 3: # export all shows except CANCELLED
e = Event()
e.summary = row["Artists"] + ": " + row["City"] + " - " + row["Venue"] + " (" + row["Country"] + ")"
status_text = show_status_list[row["Status"]]
e.description = ("Show Status: " + status_text +
"\nArrival: " + row["ArrivalTime"] +
"\nSoundcheck: " + row["SoundcheckTime"] +
"\nDoors Opening: " + row["OpeningTime"] +
"\nShow Time: " + row["ShowTime"] +
"\n\n(Cancelled Shows are excluded)\n(Generated by TourManager - do not modify)")
e.begin = datetime.datetime.fromisoformat(row["Date"]).date()
e.make_all_day()
c.events.append(e)
# export to file
export_calendar_to_file(c, workdir_path, "TourManagerShows.ics")
def export_event_calendar(df_venues, workdir_path): # EVENTS
print("export event calendar")
c = Calendar()
for i, row in df_venues.iterrows():
if row["VenueStartDate"] != "":
#print(row["VenueName"], row["VenueStartDate"], row["VenueEndDate"])
e = Event()
e.summary = row["VenueName"] #+ " (" + row["VenueCity"] + " - " + row["VenueCountry"] + ")"
e.description = ("Name: " + row["VenueName"] +
"\nCity: " + row["VenueCity"] +
"\nCountry: " + row["VenueCountry"] +
"\n\n(Generated by TourManager - do not modify)")
e.begin = datetime.datetime.fromisoformat(row["VenueStartDate"])
if row["VenueEndDate"] != row["VenueStartDate"]:
e.end = datetime.datetime.fromisoformat(row["VenueEndDate"]) + datetime.timedelta(hours=12) # + timedelta needed otherwise end day is one day before (ics 0.8.0dev)
e.make_all_day()
c.events.append(e)
# export to file
export_calendar_to_file(c, workdir_path, "TourManagerEvents.ics")
def export_event_forcast_calendar(df_venues, workdir_path): # EVENTS FORECAST
print("export event forecast calendar")
c = Calendar()
for i, row in df_venues.iterrows():
if row["VenueStartDate"] != "":
e = Event()
year = row["VenueStartDate"].split("-")[0]
e.summary = year + ": " + row["VenueName"]
e.description = ("THIS IS THE FORECAST FROM THE " + year + " EVENT.\nPlease update the event's dates."
"\n\nName: " + row["VenueName"] +
"\nCity: " + row["VenueCity"] +
"\nCountry: " + row["VenueCountry"] +
"\n\n(Generated by TourManager - do not modify)")
e.begin = datetime.datetime.fromisoformat(row["VenueStartDate"]) + datetime.timedelta(days=365) # add one year
if row["VenueEndDate"] != row["VenueStartDate"]:
e.end = datetime.datetime.fromisoformat(row["VenueEndDate"]) + datetime.timedelta(days=365, hours=12) # + timedelta needed otherwise end day is one day before (ics 0.8.0dev)
e.make_all_day()
c.events.append(e)
# export to file
export_calendar_to_file(c, workdir_path, "TourManagerEventsForecast.ics")
def export_calendar_to_file(calendar, workdir_path, filename):
export_path = os.path.join(workdir_path, filename)
with open(export_path, "w", newline="", encoding="utf-8") as my_file:
my_file.write(calendar.serialize())