diff --git a/media_ticket_generator.py b/media_ticket_generator.py new file mode 100644 index 0000000000000000000000000000000000000000..a619f5c7c3f541c028dd21474fcbd07cf6fc1fb3 --- /dev/null +++ b/media_ticket_generator.py @@ -0,0 +1,77 @@ +# requires requests==2.28.2 +# requires xmltodict=0.13.0 +# requires python-frontmatter==1.0.0 + +import requests +import xmltodict +import frontmatter +import glob +import os +import sys + +api_key = os.environ.get('REDMINE_API_KEY') + +known_uids = [] +url = 'https://chaotikum.org/conferences/all/frab.xml' +response = requests.get(url) +data = xmltodict.parse(response.content) + +for day in data['schedule']['day']: + if 'event' in day['room']: + if '@guid' in day['room']['event']: + known_uids.append(day['room']['event']['@guid']) + else: + for event in day['room']['event']: + known_uids.append(event['@guid']) + else: + for room in day['room']: + if '@guid' in room['event']: + known_uids.append(room['event']['@guid']) + else: + for event in room['event']: + known_uids.append(event['@guid']) + +files = glob.glob('_media/*.md') +for file in files: + post = frontmatter.load(file) + if 'uid' in post.keys(): + uid = post['uid'] + if uid not in known_uids: + if api_key is None: + print("No environment variable REDMINE_API_KEY present.", file=sys.stderr) + sys.exit(1) + else: + print('new uid, create ticket in redmine') + title = post['title'] + content = post.content + print('Title:' + title) + print('uid:' + uid) + print(content) + # https://www.redmine.org/projects/redmine/wiki/rest_issues + # https://www.redmine.org/projects/redmine/wiki/rest_api + # https://www.redmine.org/issues/31186 + url = f"https://redmine.chaotikum.org/issues.json?key={api_key}" + post_content = {} + post_content['issue'] = {}; + post_content['issue']["project_id"] = 38 + post_content['issue']["subject"] = title + post_content['issue']["description"] = content + post_content['issue']["custom_fields"] = [] + + uuid_field = {} + uuid_field['id'] = 11 + uuid_field['value'] = uid + uuid_field['name'] = "Video-UUID" + post_content['issue']["custom_fields"].append(uuid_field) + + speaker_field = {} + speaker_field['id'] = 8 + speaker_field['value'] = "Speaker" + speaker_field['name'] = "Sprecher" + post_content['issue']["custom_fields"].append(speaker_field) + + r = requests.post(url=url, json=post_content) + print(r.json()) + + +