This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def timeout(time_limit): | |
def decorator(func): | |
def timed_out(_signum, frame): | |
raise TestTimedOut(time_limit, frame) | |
def newfunc(*args, **kwargs): | |
try: | |
# Will only work on unix systems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def callback_router(bot, update, chat_data): | |
obj = json.loads(str(update.callback_query.data)) | |
pprint(obj) | |
if 'a' in obj: | |
action = obj['a'] | |
if action == CallbackActions.OVERVIEW: | |
finances.main(bot, update, chat_data) | |
elif action == CallbackActions.ALL_TRANSACTIONS: | |
finances.show_all(bot, update) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
userresources=$HOME/.Xresources | |
usermodmap=$HOME/.Xmodmap | |
sysresources=/etc/X11/xinit/.Xresources | |
sysmodmap=/etc/X11/xinit/.Xmodmap | |
# merge in defaults and keymaps | |
if [ -f $sysresources ]; then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def uid_from_update(update): | |
""" | |
Extract the user id from update | |
:param update: `telegram.Update` | |
:return: user_id extracted from the update | |
""" | |
user_id = None | |
try: | |
user_id = update.message.from_user.id | |
except (NameError, AttributeError): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _can_vote_again(user): | |
""" | |
:param user: User to check vote_timeout for | |
:return: Tuple of (state, remaining_time) where state is a boolean | |
""" | |
if user.last_vote: | |
delta = datetime.timedelta(seconds=const.VOTE_TIMEOUT) | |
now = datetime.datetime.now() | |
difference = now - user.last_vote | |
to_wait = max((delta - difference).seconds, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def some_handler(bot, update): | |
chat_id = update.message.chat_id | |
import urllib.request | |
import io | |
url = "https://talkpython.fm/episodes/download/110/data-democratization-with-redash.mp3" | |
response = urllib.request.urlopen(url) | |
bytestring = response.read() # a `bytes` object | |
file_like_object = io.BytesIO(bytestring) # convert `bytes` to file-like object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Traceback (most recent call last): | |
File "/usr/lib/python3.6/site-packages/python_telegram_bot-5.3.1-py3.6.egg/telegram/inputfile.py", line 83, in __init__ | |
self.mimetype = self.is_image(self.input_file_content) | |
File "/usr/lib/python3.6/site-packages/python_telegram_bot-5.3.1-py3.6.egg/telegram/inputfile.py", line 164, in is_image | |
raise TelegramError('Could not parse file content') | |
telegram.error.TelegramError: Could not parse file content | |
During handling of the above exception, another exception occurred: | |
Traceback (most recent call last): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import time | |
import random | |
from telethon import InteractiveTelegramClient | |
from telethon.tl.functions.photos import UploadProfilePhotoRequest | |
import os | |
client = InteractiveTelegramClient( | |
'test1', | |
'+400000000000', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@restricted(strict=True) | |
@run_async | |
def send_botlist(bot, update, resend=False, silent=False): | |
log.info("Re-Sending BotList..." if resend else "Updating BotList...") | |
chat_id = util.uid_from_update(update) | |
message_id = util.mid_from_update(update) | |
channel = helpers.get_channel() | |
error = False | |
def notify_admin(txt): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import logging | |
from peewee import * | |
from telegram import Update | |
from telegram import Message as TelegramMessage | |
from telegram import Chat as TelegramChat | |
from telegram import User as TelegramUser | |
from model import User |