add organizer field
This commit is contained in:
parent
71263bbefa
commit
52145d19fe
1 changed files with 76 additions and 20 deletions
|
|
@ -15,11 +15,52 @@ def strip_html_tags(text):
|
||||||
soup = BeautifulSoup(text, "html.parser")
|
soup = BeautifulSoup(text, "html.parser")
|
||||||
return soup.get_text()
|
return soup.get_text()
|
||||||
|
|
||||||
def eintopf_post_event(title, location, description, time_start, time_end):
|
def query_categories():
|
||||||
|
response = requests.get(EINTOPF_URL + "/api/v1/categories/?filters=%7B%7D", headers={
|
||||||
|
"Authorization": EINTOPF_AUTHORIZATION_TOKEN,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
})
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
return data
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def eintopf_create_category(name):
|
||||||
|
payload = {
|
||||||
|
"description": name,
|
||||||
|
"headline": name,
|
||||||
|
"name": name
|
||||||
|
}
|
||||||
|
response = requests.post(EINTOPF_URL + "/api/v1/categories/", json=payload, headers={
|
||||||
|
"Authorization": EINTOPF_AUTHORIZATION_TOKEN,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
})
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
return data['id']
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def ensure_and_get_categoryid(category):
|
||||||
|
available_categories = query_categories()
|
||||||
|
|
||||||
|
for entry in available_categories:
|
||||||
|
if entry["name"].lower() == category:
|
||||||
|
# Return the matching category ID
|
||||||
|
return entry["id"]
|
||||||
|
|
||||||
|
# If no matching category is found, create a new one
|
||||||
|
category_id = eintopf_create_category(category)
|
||||||
|
return category_id
|
||||||
|
|
||||||
|
def eintopf_post_event(event: dict):
|
||||||
payload = {
|
payload = {
|
||||||
"address": "Karlsruhe",
|
"address": "Karlsruhe",
|
||||||
"category": "",
|
"category": event['category_id'],
|
||||||
"description": strip_html_tags(description),
|
"description": strip_html_tags(event['description']),
|
||||||
"image": "",
|
"image": "",
|
||||||
"involved": [
|
"involved": [
|
||||||
{
|
{
|
||||||
|
|
@ -29,15 +70,15 @@ def eintopf_post_event(title, location, description, time_start, time_end):
|
||||||
],
|
],
|
||||||
"lat": 0,
|
"lat": 0,
|
||||||
"lng": 0,
|
"lng": 0,
|
||||||
"location": location,
|
"location": event['location'],
|
||||||
"name": title,
|
"name": event['title'],
|
||||||
"organizers": ["Anonymous"],
|
"organizers": [ event['organizer'] ],
|
||||||
"ownedBy": ["Anonymous"],
|
"ownedBy": [ event['organizer'] ],
|
||||||
"published": True,
|
"published": True,
|
||||||
"start": time_start,
|
"start": event['time_start'],
|
||||||
"end": time_end,
|
"end": event['time_end'],
|
||||||
"tags": ["karlsruhe"],
|
"tags": ["karlsruhe"],
|
||||||
"topic": "Veranstaltung"
|
"topic": event['topic_id'],
|
||||||
}
|
}
|
||||||
response = requests.post(EINTOPF_URL + "/api/v1/events/", json=payload, headers={
|
response = requests.post(EINTOPF_URL + "/api/v1/events/", json=payload, headers={
|
||||||
"Authorization": EINTOPF_AUTHORIZATION_TOKEN,
|
"Authorization": EINTOPF_AUTHORIZATION_TOKEN,
|
||||||
|
|
@ -51,7 +92,10 @@ def eintopf_post_event(title, location, description, time_start, time_end):
|
||||||
|
|
||||||
print("Beginning scraping Radar api ...")
|
print("Beginning scraping Radar api ...")
|
||||||
|
|
||||||
response = requests.get("https://radar.squat.net/api/1.2/search/events.json?fields=title,offline,date_time,body&facets[group][]=" + RADAR_GROUP_ID)
|
response = requests.get("https://radar.squat.net/api/1.2/search/events.json", params={
|
||||||
|
"fields": "title,offline,date_time,body,category,uuid,og_group_ref",
|
||||||
|
"facets[group][]=": RADAR_GROUP_ID
|
||||||
|
})
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
@ -62,17 +106,29 @@ if response.status_code == 200:
|
||||||
for event in events:
|
for event in events:
|
||||||
|
|
||||||
event = events[event]
|
event = events[event]
|
||||||
title = event["title"]
|
categories = [cat["name"] for cat in event.get("category", [])]
|
||||||
time_start = event["date_time"][0]["time_start"]
|
category_id = ensure_and_get_categoryid(categories[0])
|
||||||
time_end = event["date_time"][0]["time_end"]
|
new_event = {
|
||||||
location = event["offline"][0]['title']
|
'title': event["title"],
|
||||||
description = event["body"]['value']
|
'time_start': event["date_time"][0]["time_start"],
|
||||||
|
'time_end': event["date_time"][0]["time_end"],
|
||||||
|
'location': event["offline"][0]['title'],
|
||||||
|
'description': event["body"]['value'],
|
||||||
|
'category_id': category_id,
|
||||||
|
'topic_id': "003387f0-9f28-44e4-ab41-808007bc6586",
|
||||||
|
'uuid': event["uuid"],
|
||||||
|
'organizer': event["og_group_ref"][0]["title"]
|
||||||
|
}
|
||||||
|
|
||||||
if eintopf_post_event(title, location, description, time_start, time_end):
|
if eintopf_post_event(new_event):
|
||||||
print("Event successfully added:")
|
print("Event successfully added:")
|
||||||
print(f"Title: {title}")
|
print(f"Title: {new_event['title']}")
|
||||||
print(f"Time Start: {time_start}")
|
print(f"Time Start: {new_event['time_start']}")
|
||||||
print(f"Location: {location}")
|
print(f"Location: {new_event['location']}")
|
||||||
|
print(f"Category: {categories[0]} ({new_event['category_id']})")
|
||||||
|
print(f"Topic: Sonstiges ({new_event['topic_id']})")
|
||||||
|
print(f"UUID: {new_event['uuid']}")
|
||||||
|
print(f"Organizer: {new_event['organizer']}")
|
||||||
print('-' * 40)
|
print('-' * 40)
|
||||||
else:
|
else:
|
||||||
print("Submitting event failed")
|
print("Submitting event failed")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue