This commit is contained in:
bye 2024-11-09 11:15:08 +00:00
parent ab5a75672d
commit d163e35ba8
1 changed files with 30 additions and 0 deletions

30
main.py Normal file
View File

@ -0,0 +1,30 @@
import urllib.parse as parse
import xml.etree.ElementTree as ET
import requests
from flask import Flask, request
app = Flask(__name__)
@app.route('/convert_feed_to_oregonian_amp/')
def bring_out_feed():
# De-url encode the input
url = parse.unquote(request.args.get('url'))
oregon = requests.get(url)
content = oregon.content
root = ET.fromstring(content)
for child in root.iter('item'):
updated_url = parse.urlparse(child.find('link').text, allow_fragments=True)
if updated_url.query != '':
updated_url = updated_url._replace(query=updated_url.query + '&')
updated_url = updated_url._replace(query=updated_url.query + 'outputType=amp')
print(updated_url)
child.find('link').text = str(parse.urlunparse(updated_url))
return app.response_class(ET.tostring(root), mimetype='application/xml')
print(app.url_map)