|
|
|
|
@ -40,7 +40,7 @@ logging.basicConfig( |
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
OPTION, LINK, LINE, PHOTO, END = range(5) |
|
|
|
|
OPTION, LINK, JSON, LINE, PHOTO, END = range(6) |
|
|
|
|
|
|
|
|
|
daten = {} |
|
|
|
|
|
|
|
|
|
@ -235,7 +235,7 @@ def start(update: Update, context: CallbackContext) -> None: |
|
|
|
|
|
|
|
|
|
def banner(update: Update, context: CallbackContext) -> None: |
|
|
|
|
"""Sends explanation on how to use the bot.""" |
|
|
|
|
reply_keyboard = [['LINK', 'LINE']] |
|
|
|
|
reply_keyboard = [['JSON', 'LINK', 'LINE']] |
|
|
|
|
|
|
|
|
|
daten = {} |
|
|
|
|
update.message.reply_text( |
|
|
|
|
@ -260,6 +260,9 @@ def option(update: Update, context: CallbackContext) -> int: |
|
|
|
|
|
|
|
|
|
daten['type'] = update.message.text |
|
|
|
|
|
|
|
|
|
if daten['type'] == "JSON": |
|
|
|
|
return JSON |
|
|
|
|
|
|
|
|
|
if daten['type'] == "LINK": |
|
|
|
|
return LINK |
|
|
|
|
|
|
|
|
|
@ -311,6 +314,8 @@ def urlParser(update: Update, context: CallbackContext) -> int: |
|
|
|
|
|
|
|
|
|
def lineParser(update: Update, context: CallbackContext) -> int: |
|
|
|
|
"""Sends explanation on how to use the bot.""" |
|
|
|
|
update.message.reply_text(f'{update.message.chat_id} 2') |
|
|
|
|
|
|
|
|
|
text = update.message.text |
|
|
|
|
text = text.split(",") |
|
|
|
|
|
|
|
|
|
@ -319,25 +324,36 @@ def lineParser(update: Update, context: CallbackContext) -> int: |
|
|
|
|
# config = yaml.load(f) |
|
|
|
|
# nummer startLatitude startLongitude titel picture formattedAddress completed missions date bg-link onyx description lengthKMeters |
|
|
|
|
bannerInfos = {} |
|
|
|
|
bannerInfos['nummer'] = text[0] |
|
|
|
|
bannerInfos['startLatitude'] = text[8] |
|
|
|
|
bannerInfos['startLongitude'] = text[9] |
|
|
|
|
bannerInfos['titel'] = text[1] |
|
|
|
|
bannerInfos['picture'] = None |
|
|
|
|
bannerInfos['nummer'] = text[4] |
|
|
|
|
bannerInfos['startLatitude'] = text[0] |
|
|
|
|
bannerInfos['startLongitude'] = text[1] |
|
|
|
|
bannerInfos['titel'] = text[2] |
|
|
|
|
bannerInfos['picture'] = text[3] |
|
|
|
|
bannerInfos['formattedAddress'] = None |
|
|
|
|
bannerInfos['completed'] = None |
|
|
|
|
bannerInfos['missions'] = text[2] |
|
|
|
|
bannerInfos['date'] = None |
|
|
|
|
bannerInfos['completed'] = text[6] |
|
|
|
|
bannerInfos['missions'] = text[7] |
|
|
|
|
bannerInfos['date'] = text[8] |
|
|
|
|
p = re.compile(r'^https:\/\/bannergress.com\/banner\D[\w\d-]*', re.IGNORECASE) |
|
|
|
|
if p.match(text[7]): |
|
|
|
|
bannerInfos['bg-link'] = text[7] |
|
|
|
|
if p.match(text[9]): |
|
|
|
|
bannerInfos['bg-link'] = text[9] |
|
|
|
|
else: |
|
|
|
|
bannerInfos['bg-link'] = None |
|
|
|
|
bannerInfos['onyx'] = None |
|
|
|
|
bannerInfos['onyx'] = text[10] |
|
|
|
|
bannerInfos['description'] = None |
|
|
|
|
bannerInfos['lengthKMeters'] = None |
|
|
|
|
daten['bannerInfos'] = bannerInfos |
|
|
|
|
|
|
|
|
|
verarbeitung(update, context) |
|
|
|
|
|
|
|
|
|
return ConversationHandler.END |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fileParser(update: Update, context: CallbackContext) -> int: |
|
|
|
|
"""Sends explanation on how to use the bot.""" |
|
|
|
|
update.message.reply_text(f'{update.message.chat_id} 3') |
|
|
|
|
|
|
|
|
|
daten['json-file'] = context.bot.getFile(update.message.document.file_id) |
|
|
|
|
|
|
|
|
|
update.message.reply_text("Sende mir Banner Bild") |
|
|
|
|
|
|
|
|
|
return PHOTO |
|
|
|
|
@ -347,27 +363,46 @@ def getPhoto(update: Update, context: CallbackContext) -> int: |
|
|
|
|
|
|
|
|
|
update.message.reply_text(f'{update.message.chat_id} 4') |
|
|
|
|
|
|
|
|
|
url = context.bot.getFile(update.message.photo[-1].file_id)['file_path'] |
|
|
|
|
url = requests.get(daten['json-file']['file_path']) |
|
|
|
|
text = url.text |
|
|
|
|
obj = json.loads(text) |
|
|
|
|
|
|
|
|
|
import datetime |
|
|
|
|
now = datetime.datetime.now().year |
|
|
|
|
|
|
|
|
|
daten['bannerInfos']['picture'] = url |
|
|
|
|
|
|
|
|
|
daten['bannerInfos']['date'] = now |
|
|
|
|
daten['bannerInfos']['bg-link'] = None |
|
|
|
|
daten['bannerInfos']['onyx'] = 0 |
|
|
|
|
daten['bannerInfos']['description'] = None |
|
|
|
|
daten['bannerInfos']['lengthKMeters'] = None |
|
|
|
|
|
|
|
|
|
bannerInfos = {} |
|
|
|
|
bannerInfos['nummer'] = None |
|
|
|
|
bannerInfos['startLatitude'] = obj['missions'][0]['portals'][0]['location']['latitude'] |
|
|
|
|
bannerInfos['startLongitude'] = obj['missions'][0]['portals'][0]['location']['longitude'] |
|
|
|
|
bannerInfos['titel'] = obj['missionSetName'] |
|
|
|
|
bannerInfos['picture'] = context.bot.getFile(update.message.photo[-1].file_id)['file_path'] |
|
|
|
|
bannerInfos['formattedAddress'] = None |
|
|
|
|
bannerInfos['completed'] = None |
|
|
|
|
bannerInfos['missions'] = obj['plannedBannerLength'] |
|
|
|
|
bannerInfos['date'] = now |
|
|
|
|
bannerInfos['bg-link'] = None |
|
|
|
|
bannerInfos['onyx'] = 0 |
|
|
|
|
bannerInfos['description'] = obj['missionSetDescription'] |
|
|
|
|
bannerInfos['lengthKMeters'] = None |
|
|
|
|
daten['bannerInfos'] = bannerInfos |
|
|
|
|
|
|
|
|
|
verarbeitung(update, context) |
|
|
|
|
|
|
|
|
|
return ConversationHandler.END |
|
|
|
|
|
|
|
|
|
def verarbeitung(update: Update, context: CallbackContext): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
agent = loadAgentConfig() |
|
|
|
|
|
|
|
|
|
if daten['type'] == "JSON": |
|
|
|
|
logger.info("JSON PArse MODE") |
|
|
|
|
if daten['bannerInfos']['nummer'] is None: |
|
|
|
|
daten['bannerInfos']['nummer'] = agent['banner-completed'] |
|
|
|
|
if daten['bannerInfos']['formattedAddress'] is None: |
|
|
|
|
daten['bannerInfos']['formattedAddress'] = getFormattedAddress(daten['bannerInfos']['startLatitude'], daten['bannerInfos']['startLongitude']) |
|
|
|
|
if daten['bannerInfos']['completed'] is None: |
|
|
|
|
daten['bannerInfos']['completed'] = int(agent['completed-mission']) + int(daten['bannerInfos']['missions']) |
|
|
|
|
uploadJsonToGDrive(daten) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if daten['type'] == "LINK": |
|
|
|
|
@ -394,7 +429,6 @@ def verarbeitung(update: Update, context: CallbackContext): |
|
|
|
|
daten['bannerInfos']['lengthKMeters'] |
|
|
|
|
if daten['type'] == "LINE": |
|
|
|
|
logger.info("LINE PArse MODE") |
|
|
|
|
daten['bannerInfos']['nummer'] = agent['banner-completed'] |
|
|
|
|
if daten['bannerInfos']['formattedAddress'] is None: |
|
|
|
|
daten['bannerInfos']['formattedAddress'] = getFormattedAddress(daten['bannerInfos']['startLatitude'], daten['bannerInfos']['startLongitude']) |
|
|
|
|
|
|
|
|
|
@ -407,8 +441,6 @@ def verarbeitung(update: Update, context: CallbackContext): |
|
|
|
|
daten['bannerInfos']['lengthKMeters'] = daten['bannerInfos']['lengthKMeters'] / 1000 |
|
|
|
|
else: |
|
|
|
|
daten['bannerInfos']['lengthKMeters'] |
|
|
|
|
daten['bannerInfos']['completed'] = int(agent['completed-mission']) + int( daten['bannerInfos']['missions']) |
|
|
|
|
print() |
|
|
|
|
|
|
|
|
|
uploadPictureToGDrive(daten) |
|
|
|
|
|
|
|
|
|
@ -792,15 +824,17 @@ def main() -> None: |
|
|
|
|
entry_points=[CommandHandler('banner', banner)], |
|
|
|
|
# Filters.document.file_extension("json") & Filters.user(username="@r3f1Zul"), fileParser)], |
|
|
|
|
states= { |
|
|
|
|
OPTION: [MessageHandler(Filters.regex('^(LINK|LINE)$'), option)], |
|
|
|
|
LINK: [MessageHandler(Filters.regex(re.compile(r'^https:\/\/bannergress.com\/banner\D[\w\d-]*', re.IGNORECASE)) & (Filters.user(username="@azraelis") | Filters.user(username="@r3f1Zul")), urlParser)], |
|
|
|
|
LINE: [MessageHandler((Filters.user(username="@azraelis") | Filters.user(username="@r3f1Zul")) & (~Filters.command), lineParser)], |
|
|
|
|
PHOTO: [MessageHandler(Filters.photo & (Filters.user(username="@azraelis") | Filters.user(username="@r3f1Zul")), getPhoto)] |
|
|
|
|
OPTION: [MessageHandler(Filters.regex('^(JSON|LINK|LINE)$'), option)], |
|
|
|
|
LINK: [MessageHandler(Filters.regex(re.compile(r'^https:\/\/bannergress.com\/banner\D[\w\d-]*', re.IGNORECASE)) & Filters.user(username="@r3f1Zul"), urlParser)], |
|
|
|
|
JSON: [MessageHandler(Filters.document.file_extension("json") & Filters.user(username="@r3f1Zul"), fileParser)], |
|
|
|
|
LINE: [MessageHandler(Filters.regex(re.compile(r'^[0-9]+.[0-9]+,', re.IGNORECASE)) & Filters.user(username="@r3f1Zul"), lineParser)], |
|
|
|
|
PHOTO: [MessageHandler(Filters.photo & Filters.user(username="@azraelis"), getPhoto)] |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
fallbacks=[CommandHandler('cancel', cancel)], |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dispatcher.add_handler(conv_handler) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|