splitting to separate functions
This commit is contained in:
parent
8d6005eec1
commit
b248582193
39
bot.py
39
bot.py
@ -40,13 +40,13 @@ def get_sticker_setid(document):
|
|||||||
if hasattr(a, "stickerset"):
|
if hasattr(a, "stickerset"):
|
||||||
stickerset = a.stickerset
|
stickerset = a.stickerset
|
||||||
if stickerset is None:
|
if stickerset is None:
|
||||||
dllog.info("document %s is not a sticker", document.id)
|
dllog.debug("document %s is not a sticker", document.id)
|
||||||
return None, None
|
return None, None
|
||||||
if isinstance(stickerset, types.InputStickerSetID):
|
if isinstance(stickerset, types.InputStickerSetID):
|
||||||
log.info("document %s is a normal sticker", document.id)
|
log.debug("document %s is a normal sticker", document.id)
|
||||||
return str(stickerset.id), stickerset
|
return str(stickerset.id), stickerset
|
||||||
if isinstance(stickerset, types.InputStickerSetEmpty):
|
if isinstance(stickerset, types.InputStickerSetEmpty):
|
||||||
dllog.info("document %s is an inline sticker", document.id)
|
dllog.debug("document %s is an inline sticker", document.id)
|
||||||
return "inline", stickerset
|
return "inline", stickerset
|
||||||
|
|
||||||
def fetch_dialogs(client):
|
def fetch_dialogs(client):
|
||||||
@ -57,9 +57,7 @@ def fetch_dialogs(client):
|
|||||||
log.info(dialog.stringify())
|
log.info(dialog.stringify())
|
||||||
yield dialog
|
yield dialog
|
||||||
|
|
||||||
def main(client):
|
def process_archive(archive, stickerset_seen=set()):
|
||||||
stickerset_seen=set()
|
|
||||||
for sticker_archive in fetch_dialogs(client):
|
|
||||||
for msg in client.iter_messages(sticker_archive, limit=None):
|
for msg in client.iter_messages(sticker_archive, limit=None):
|
||||||
log.debug(msg)
|
log.debug(msg)
|
||||||
if not hasattr(msg, "media"):
|
if not hasattr(msg, "media"):
|
||||||
@ -75,7 +73,7 @@ def main(client):
|
|||||||
elif dldir is not None:
|
elif dldir is not None:
|
||||||
download_sticker(client, msg.media.document)
|
download_sticker(client, msg.media.document)
|
||||||
if setid.id not in stickerset_seen:
|
if setid.id not in stickerset_seen:
|
||||||
log.debug("preparing to download whole stickerset %s as %s", setid, dldir)
|
log.info("preparing to download whole stickerset %s as %s", setid, dldir)
|
||||||
stickerset_seen.add(setid.id)
|
stickerset_seen.add(setid.id)
|
||||||
try:
|
try:
|
||||||
for doc in client(functions.messages.GetStickerSetRequest(stickerset=setid,hash=0)).documents:
|
for doc in client(functions.messages.GetStickerSetRequest(stickerset=setid,hash=0)).documents:
|
||||||
@ -88,28 +86,12 @@ def main(client):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error("somethin wrong happened during checking message: %s", msg.stringify(), exc_info=e)
|
log.error("somethin wrong happened during checking message: %s", msg.stringify(), exc_info=e)
|
||||||
|
|
||||||
# for doc in stickers_inline:
|
|
||||||
# try:
|
|
||||||
# download_sticker(client, doc)
|
|
||||||
# except Exception as e:
|
|
||||||
# log.critical("ouchie: %s", exc_info=e)
|
|
||||||
|
|
||||||
# for stickerset in stickers_sets.values():
|
|
||||||
# try:
|
|
||||||
# for doc in client(functions.messages.GetStickerSetRequest(stickerset=stickerset,hash=0)).documents:
|
|
||||||
# try:
|
|
||||||
# download_sticker(client, doc)
|
|
||||||
# except Exception as e:
|
|
||||||
# log.critical("oops: %s", exc_info=e)
|
|
||||||
# except errors.rpcerrorlist.StickersetInvalidError:
|
|
||||||
# log.warning("sadly, stickerset %s no longer exists", stickerset.id)
|
|
||||||
# except Exception as e:
|
|
||||||
# log.critical("omg: %s", exc_info=e)
|
|
||||||
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
log.debug("opening %s", repr("config/bot.yaml"))
|
log.debug("opening %s", repr("config/bot.yaml"))
|
||||||
with open("config/bot.yaml") as cfgstream:
|
with open("config/bot.yaml") as cfgstream:
|
||||||
cfg = yaml.safe_load(cfgstream)
|
cfg = yaml.safe_load(cfgstream)
|
||||||
@ -119,14 +101,9 @@ log.debug("starting client with id %s and hash %s", app['id'], app['hash'])
|
|||||||
client = TelegramClient('env/gentoo_session', app['id'], app['hash'])
|
client = TelegramClient('env/gentoo_session', app['id'], app['hash'])
|
||||||
client.start()
|
client.start()
|
||||||
log.debug(client.get_me().stringify())
|
log.debug(client.get_me().stringify())
|
||||||
stickers_sets=dict()
|
|
||||||
stickers_favorites=set()
|
|
||||||
stickers_inline=list()
|
|
||||||
sticker_archives=list()
|
|
||||||
try:
|
try:
|
||||||
main(client)
|
for sticker_archive in fetch_dialogs(client):
|
||||||
|
process_archive(sticker_archive)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user