Browse Source

added end date entry

main
Cailean Finn 7 months ago
parent
commit
7075f7aa1b
  1. 15
      app.py
  2. 2
      templates/newsletter.html

15
app.py

@ -102,6 +102,7 @@ class WikiApp(Flask):
def fetch_events(self, pub_date, future_date): def fetch_events(self, pub_date, future_date):
all_events = self.fetch_all_events(pub_date, future_date) all_events = self.fetch_all_events(pub_date, future_date)
print(all_events)
if not all_events: if not all_events:
return {} return {}
else: else:
@ -140,9 +141,8 @@ class WikiApp(Flask):
opp_page_list = {} opp_page_list = {}
categories = ['Events'] categories = ['Events']
for category in categories: for category in categories:
response = requests.get(self.MEDIAWIKI_BASE_URL + self.BASE_API, params={'action': 'ask', 'query': '[[Concept:'+category+']] [[Event:Date::<=' + future_date.strftime("%Y-%m-%d") + ']] [[Event:Date::>='+ pub_date.strftime("%Y-%m-%d") + ']] |?Event:Date|?Event:Name|?Event:Location|?Event:Organiser/s|?Event:Source', 'format': 'json', 'formatversion': '2'}) response = requests.get(self.MEDIAWIKI_BASE_URL + self.BASE_API, params={'action': 'ask', 'query': '[[Concept:'+category+']] [[Event:Date::<=' + future_date.strftime("%Y-%m-%d") + ']] [[Event:Date::>='+ pub_date.strftime("%Y-%m-%d") + ']] |?Event:Date|?Event:EndDate|?Event:Name|?Event:Location|?Event:Organiser/s|?Event:Source', 'format': 'json', 'formatversion': '2'})
data = response.json() data = response.json()
opp_info = {} opp_info = {}
if not data['query']['results']: if not data['query']['results']:
return {} return {}
@ -155,11 +155,20 @@ class WikiApp(Flask):
deadline = deadline[2:] deadline = deadline[2:]
lol = datetime.strptime(deadline, "%Y/%m/%d") lol = datetime.strptime(deadline, "%Y/%m/%d")
formatted_deadline = lol.strftime("%d-%m-%Y") formatted_deadline = lol.strftime("%d-%m-%Y")
try:
endDate = page_data['printouts']['Event:EndDate'][0]['raw']
endDate = endDate[2:]
lol_2 = datetime.strptime(endDate, "%Y/%m/%d")
formatted_EndDate = lol_2.strftime("%d-%m-%Y")
except:
formatted_EndDate = "(っ °Д °;)っ"
location = page_data['printouts']['Event:Location'][0] location = page_data['printouts']['Event:Location'][0]
source = page_data['printouts']['Event:Source'][0] source = page_data['printouts']['Event:Source'][0]
org = page_data['printouts']['Event:Organiser/s'][0]['fulltext'] org = page_data['printouts']['Event:Organiser/s'][0]['fulltext']
opp_info = {'pagetitle': page_title, 'name': name, 'deadline': formatted_deadline, 'location': location, 'source' : source, 'org': org, 'text': ''} opp_info = {'pagetitle': page_title, 'name': name, 'deadline': formatted_deadline, 'endDate': formatted_EndDate,'location': location, 'source' : source, 'org': org, 'text': ''}
if type not in opp_page_list: if type not in opp_page_list:
opp_page_list[type] = [] opp_page_list[type] = []

2
templates/newsletter.html

@ -18,7 +18,7 @@
<h4 class='event-name'><b>{{ data.name }}</b></h4> <h4 class='event-name'><b>{{ data.name }}</b></h4>
<p class='event-org'><b>Organiser/s: </b>{{ data.org }}</p> <p class='event-org'><b>Organiser/s: </b>{{ data.org }}</p>
<p class='event-location'><b>Location: </b>{{ data.location }}</p> <p class='event-location'><b>Location: </b>{{ data.location }}</p>
<p class='event-deadline'><b>Date: </b>{{ data.deadline }}</p> <p class='event-deadline'><b>Date: </b>{{ data.deadline }} &#8594; {{ data.endDate}}</p>
<p class='event-text'>{{ data.text }}</p> <p class='event-text'>{{ data.text }}</p>
<a href={{ data.source }} target='_blank'><p class='event-link'><b>Link ↗</b></p></a> <a href={{ data.source }} target='_blank'><p class='event-link'><b>Link ↗</b></p></a>
</div> </div>

Loading…
Cancel
Save