-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_wiki_meeting_page.py
227 lines (160 loc) · 7.05 KB
/
create_wiki_meeting_page.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# Treffen-Seite anlegen einen Tag nach jedem 1. und 3. Freitag im Monat
from datetime import date, timedelta
import requests as req
import logging
# Logging
LOG_FILENAME = 'log_create_wiki_meeting_page.log'
FORMAT = "%(asctime)-15s %(message)s"
logging.basicConfig(filename=LOG_FILENAME,format=FORMAT,level=logging.INFO)
template_text = """
# Treffen DATE_PLACEHOLDER
**Termin:** 19:00 Uhr Start und Neulingsbegrüßung, 19:30 Uhr Eröffnung der Tagesordnung
**Ort:** Hackerspace Bremen e.V. ([Anfahrt](https://www.hackerspace-bremen.de/anfahrt/))
## Tagesordnung
### Neulingsbegrüßung (19:00 – 19:30 Uhr)
- Abfragen:
- ist jemand neu?
- hat jemand Fragen?
- braucht jemand Hilfe?
- Einführung:
- kurze Vorstellungsrunde
- Funktionsweise der Freifunk Community
- wie verschieden können die Beiträge/Funktionen eines Freifunker sein (TOP Aufgaben)
- Ablauf des Treffens
---
### Top 1: Termine übertragen
- Ins letzte Protokoll gucken und Termine übertragen
### Top 2
...
### Termine
Müssen noch aus dem letzten Protokoll übernommen werden!
## Regelmäßige TOPs
### Aufgaben
- hat jemand Kapazität / möchte jemand helfen?
- ein paar Aufgaben von https://tasks.ffhb.de/ anbieten
### Rechte
- Zustand
- Zufriedenheit
- Änderungen?
### Treffen abschließen
- Info zu Treffen aktualisieren
- Protokoll aus Pad ins Wiki kopieren
- neue Wiki-Seite für nächstes Treffen mit Standard-TOPs anlegen
- [Treffen auf Wiki-Homepage anpassen](https://wiki.bremen.freifunk.net/Home)
- Topic im IRC anpassen
- Aufräumen!
- Müll weg
- Kabel zurück
## Protokoll
Live Kollaboration:
* Schreiblink: https://hackmd.io/AwDgnA7ATArKC0BGGBjAzPALAUzSeARgYgGzxQAmEFFwiKBEKAhkA===?edit
* Side-by-side: https://hackmd.io/AwDgnA7ATArKC0BGGBjAzPALAUzSeARgYgGzxQAmEFFwiKBEKAhkA===?both
* Leselink: https://hackmd.io/AwDgnA7ATArKC0BGGBjAzPALAUzSeARgYgGzxQAmEFFwiKBEKAhkA===?view
# Freifunk Bremen - Protokoll-Pad
### Anwesende
"""
def main():
d = date.today()
#d = date(2020, 6, 6) # debug
host = 'https://wiki.bremen.freifunk.net'
path = "/Treffen"
user = 'wellenfunk'
passwd = 'foobar'
if is_day_after_meeting(d) and meeting_page_is_not_yet_created(user, passwd, host, path, next_1st_and_3rd_friday(d)[0].strftime("%Y_%m_%d")):
logging.info("Day after Meeting. Let's go!")
next_two_meetings = next_1st_and_3rd_friday(d)
logging.info("Next meetings: "+next_two_meetings[0].strftime("%Y_%m_%d")+" "+next_two_meetings[1].strftime("%Y_%m_%d"))
print("Next meetings: "+next_two_meetings[0].strftime("%Y_%m_%d")+" "+next_two_meetings[1].strftime("%Y_%m_%d"))
edit_latest_page(user, passwd, host, path)
create_meeting_page(next_two_meetings[0], user, passwd, host, path, template_text)
else:
logging.info("Nothing done.")
print("Nothing done.")
def is_day_after_meeting(d):
# check if saturday after 1. or 3. friday
is_saturday = True if (d.weekday() == 5) else False
was_first_week = True if (d - timedelta(days=1)).day <= 7 else False
was_third_week = True if (((d - timedelta(days=1)).day >= 15) and ((d - timedelta(days=1)).day < 22)) else False
return True if (is_saturday and (was_first_week or was_third_week)) else False
def next_1st_and_3rd_friday(d):
# Days until next friday
days_until_friday = (4 - d.weekday()) % 7
date_next_friday = d + timedelta(days=days_until_friday)
next_month = ((d.month % 12) + 1)
first_day_of_next_month = date(d.year, next_month, 1)
days_until_friday = (4 - first_day_of_next_month.weekday()) % 7
date_next_month_friday = first_day_of_next_month + timedelta(days= days_until_friday)
# Cases for each week
if (date_next_friday.day <= 7):
return(date_next_friday, date_next_friday+timedelta(days=14))
elif(date_next_friday.day > 7 and date_next_friday.day < 15):
return(date_next_friday+timedelta(days=7), date_next_month_friday)
elif(date_next_friday.day >= 15 and date_next_friday.day < 22):
return(date_next_friday, date_next_month_friday)
else:
return(date_next_month_friday, date_next_month_friday+timedelta(days=14))
def test_print_fridays():
try:
for j in range(12):
for i in range(28):
d = date(2020, j+1, i+1) # debug
print(i+1, j+1, next_first_friday(d))
except ValueError:
pass
def meeting_page_is_not_yet_created(user, passwd, host, path, page):
url = host+"/create"+path+"/"+page
resp_check = req.get(url, auth=(user, passwd))
title = resp_check.text
title = title[title.find('<title>') + 7 : title.find('</title>')]
if title == "Create a new page":
logging.info("Page not existing.")
print("Page not existing.")
return True
else:
logging.info("Page is existing. Good bye.")
print("Page is existing. Good bye.")
return False
def create_meeting_page(meeting_date, user, passwd, host, path, template_text):
logging.info("Creating Page.")
print("Creating Page.")
demo_title = "aunicornflyingonablueswinginrocketcat"
create_post_req = {"page":demo_title,
"path": path,
"format":"markdown",
"content":template_text.replace("DATE_PLACEHOLDER", meeting_date.strftime("%d.%m.%Y")),
"message":"Created+"+demo_title}
resp_create = req.post(host+"/create", data = create_post_req, auth=(user, passwd))
# Change Name (BUG: Its not possible to init a page with '_' in its name
rename_post_req = {"rename":path+"/"+meeting_date.strftime("%Y_%m_%d"),
"message":"Renamed+"+demo_title+"+to+"+meeting_date.strftime("%Y_%m_%d")}
resp_rename = req.post(host+"/rename"+path+"/"+demo_title, data = rename_post_req, auth=(user, passwd))
logging.info("Page created. Have a nice day.")
print("Page created. Have a nice day.")
def get_last_protocol_date():
#https://wiki.ffhb.de/pages/Treffen/
resp_create = req.get("https://wiki.ffhb.de/pages/Treffen/")
matched_lines = [line for line in resp_create.text.split('\n') if '<li><a href="' in line]
last_date = matched_lines[-2][22:32] # get date
return last_date
def edit_latest_page(user, passwd, host, path):
logging.info("Creating Page latest.")
print("Creating Page logging.")
title = "latest"
last_date = get_last_protocol_date()
neuer_text = """
# Latest
# Bearbeitungshinweis
Dies ist das eingebundene Protokoll des letzten Treffens.
Du kannst das Protokoll unter [[DATE_PLACEHOLDER_SCORED|DATE_PLACEHOLDER_SCORED]] bearbeiten
---
[[include:/Treffen/DATE_PLACEHOLDER_SCORED]]
"""
neuer_text=neuer_text.replace("DATE_PLACEHOLDER_SCORED", last_date)
create_post_req = {"page":title,
"path": path,
"format":"markdown",
"content": neuer_text.replace("DATE_PLACEHOLDER_SCORED", last_date),
"message":"Edited latest"}
resp_create = req.post(host+"/edit"+path+"/"+title, data = create_post_req, auth=(user, passwd))
if __name__ == "__main__":
main()