|
|
|
|
@ -484,6 +484,90 @@ def publishBannerInChannel(update: Update, context: CallbackContext, daten): |
|
|
|
|
context.bot.send_photo("@KnallfroschOnTour", photo=open(daten['bannerInfos']['file_path'], 'rb'), caption=text, parse_mode=ParseMode.HTML) |
|
|
|
|
update.message.reply_text("Fertig") |
|
|
|
|
|
|
|
|
|
def uploadJsonToGDrive(daten): |
|
|
|
|
print() |
|
|
|
|
import requests |
|
|
|
|
import time |
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
agent = loadAgentConfig() |
|
|
|
|
|
|
|
|
|
fname = daten['bannerInfos']['titel'].replace(" ", "-") |
|
|
|
|
fname = fname.replace("/", "") |
|
|
|
|
fname = fname.replace("[", "") |
|
|
|
|
fname = fname.replace("]", "") |
|
|
|
|
|
|
|
|
|
fname = fname.replace("ü", "ue") |
|
|
|
|
fname = fname.replace("ö", "oe") |
|
|
|
|
fname = fname.replace("ä", "ae") |
|
|
|
|
fname = fname.replace("ń", "n") |
|
|
|
|
|
|
|
|
|
nr = int(daten['bannerInfos']['nummer']) |
|
|
|
|
date = int(daten['bannerInfos']['date']) |
|
|
|
|
file_path = f'json/{nr:05d}_{fname}_{date}.json' |
|
|
|
|
daten['bannerInfos']['json_file_path'] = file_path |
|
|
|
|
daten['bannerInfos']['json_filename'] =f"{nr:05d}_{fname}_{date}.json" |
|
|
|
|
|
|
|
|
|
print(file_path) |
|
|
|
|
|
|
|
|
|
url = requests.get(daten['json-file']['file_path']) |
|
|
|
|
text = url.text |
|
|
|
|
obj = json.loads(text) |
|
|
|
|
|
|
|
|
|
with open(daten['bannerInfos']['json_file_path'], 'w', encoding='utf-8') as f: |
|
|
|
|
json.dump(obj, f, ensure_ascii=False, indent=4) |
|
|
|
|
|
|
|
|
|
time.sleep(2) |
|
|
|
|
|
|
|
|
|
from pydrive.auth import GoogleAuth |
|
|
|
|
from pydrive.drive import GoogleDrive |
|
|
|
|
|
|
|
|
|
gauth = GoogleAuth() |
|
|
|
|
|
|
|
|
|
# Try to load saved client credentials |
|
|
|
|
gauth.LoadCredentialsFile("GoogleDriveCredentials.txt") |
|
|
|
|
if gauth.credentials is None: |
|
|
|
|
# Authenticate if they're not there |
|
|
|
|
gauth.LocalWebserverAuth() |
|
|
|
|
elif gauth.access_token_expired: |
|
|
|
|
# Refresh them if expired |
|
|
|
|
print("Google Drive Token Expired, Refreshing") |
|
|
|
|
gauth.Refresh() |
|
|
|
|
else: |
|
|
|
|
# Initialize the saved creds |
|
|
|
|
gauth.Authorize() |
|
|
|
|
# Save the current credentials to a file |
|
|
|
|
gauth.SaveCredentialsFile("GoogleDriveCredentials.txt") |
|
|
|
|
drive = GoogleDrive(gauth) |
|
|
|
|
|
|
|
|
|
file1 = drive.CreateFile({'parents': [{'id': '1nZJEAGh1OdzveuKdgHqA4P9yaSorDLYH'}], 'title': daten['bannerInfos']['json_filename'], 'mimeType':'application/json'}) |
|
|
|
|
|
|
|
|
|
file1.SetContentFile(daten['bannerInfos']['json_file_path']) |
|
|
|
|
file1.Upload() |
|
|
|
|
|
|
|
|
|
def publishBannerInChannel(update: Update, context: CallbackContext, daten): |
|
|
|
|
from telegram.utils.helpers import escape_markdown |
|
|
|
|
print() |
|
|
|
|
|
|
|
|
|
# https://umap.openstreetmap.de/de/map/r3f1zul-on-tour_19893?feature=xmas%20panda#18/53.50648/13.74733 |
|
|
|
|
t = daten['bannerInfos']['titel'].replace(" ", "%20") |
|
|
|
|
place = f"{daten['bannerInfos']['formattedAddress']['place']}, {daten['bannerInfos']['formattedAddress']['country']}" |
|
|
|
|
#place = f"Orainienburg, Deutschalnd" |
|
|
|
|
link = f"https://umap.openstreetmap.de/de/map/r3f1zul-on-tour_19893?feature={t}#18/{daten['bannerInfos']['startLatitude']}/{daten['bannerInfos']['startLongitude']}" |
|
|
|
|
text = f"""<b>{daten['bannerInfos']['titel']}</b>\n\n<b>Banner-Nr:</b> {daten['bannerInfos']['nummer']}\n<b>Unique Mission Completed:</b> {daten['bannerInfos']['completed']} (+{daten['bannerInfos']['missions']})\n<b>Place:</b> {place}\n\n<a href="{link}">MAP</a>\n""" |
|
|
|
|
|
|
|
|
|
print() |
|
|
|
|
|
|
|
|
|
# text = text.replace("-", "\-") |
|
|
|
|
# text = text.replace("(", "\(") |
|
|
|
|
# text = text.replace(")", "\)") |
|
|
|
|
# text = text.replace(".", "\.") |
|
|
|
|
|
|
|
|
|
# msg = escape_markdown(text, version=2) |
|
|
|
|
context.bot.send_photo("@r3f1sworld", photo=open(daten['bannerInfos']['file_path'], 'rb'), caption=text, parse_mode=ParseMode.HTML, protect_content=True) |
|
|
|
|
update.message.reply_text("Fertig") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getPublicLink(daten): |
|
|
|
|
import os |
|
|
|
|
|