Skip to content

Instantly share code, notes, and snippets.

View artemrys's full-sized avatar
:octocat:

Artem Rys artemrys

:octocat:
View GitHub Profile
@artemrys
artemrys / child_process.py
Last active December 22, 2018 18:35
exit_try_except_finally_1.py
import sys
def some_func():
...
def _child_process(target):
try:
target()
@artemrys
artemrys / bot.py
Last active December 22, 2018 18:46
python_telegram_bot_heroku_1
import logging
import os
import random
import sys
from telegram.ext import Updater, CommandHandler
# Enabling logging
logging.basicConfig(level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
@artemrys
artemrys / Dockerfile
Created December 13, 2018 23:15
python_telegram_bot_heroku_2
FROM python:3.7
RUN pip install python-telegram-bot
RUN mkdir /app
ADD . /app
WORKDIR /app
CMD python /app/bot.py
@artemrys
artemrys / save_file_from_unsplash_and_send_it_to_bot.py
Last active June 4, 2020 23:24
Save file from Unsplash and send it to Telegram bot
import requests
import os
r = requests.get("https://images.unsplash.com/photo-1452857576997-f0f12cd77844?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2850&q=80")
with open("photo.jpg", "wb") as f:
f.write(r.content)
requests.post(
"https://api.telegram.org/bot<TOKEN>/sendPhoto?chat_id=<chat_id>",
files={"photo": open("photo.jpg", "rb")}
@artemrys
artemrys / io_file_from_unsplash_and_send_it_to_bot.py
Last active June 4, 2020 23:24
IO file from Unsplash and send it to Telegram bot
import requests
import io
r = requests.get("https://images.unsplash.com/photo-1452857576997-f0f12cd77844?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2850&q=80")
with io.BytesIO() as buf:
buf.write(r.content)
buf.seek(0)
requests.post(
"https://api.telegram.org/bot<TOKEN>/sendPhoto?chat_id=<chat_id>",
@artemrys
artemrys / io_file_from_config_server_and_parse_it.py
Last active January 5, 2023 13:26
IO file from Config Server and parse it
import io
import jprops
def get_properties_from_config_server(link):
r = requests.get(link)
f = io.StringIO(r.text)
props = jprops.load_properties(f)
return props
@artemrys
artemrys / multiplication_magic.py
Last active December 27, 2018 11:21
Python multiplication magic
print(3 * 3)
# 9
print((3).__mul__(3))
# 9
print("Abc" * 3)
# 'AbcAbcAbc'
print("Abc".__mul__(3))
# 'AbcAbcAbc'
print(3 * "Abc")
# 'AbcAbcAbc'
@artemrys
artemrys / multiplication_magic.py
Created December 27, 2018 11:22
Python multiplication magic 2
print((3).__mul__("Abc"))
# NotImplemented
@artemrys
artemrys / celery_app.py
Last active January 10, 2019 00:15
Simple celery application
from celery import Celery
app = Celery(
"app",
broker="amqp://guest@localhost//",
backend="rpc",
)
@app.task
def add(x, y):
@artemrys
artemrys / app.py
Last active January 20, 2019 20:16
Celery External Call using RabbitMQ
import json
from celery import Celery
from celery import bootsteps
from kombu import Consumer, Exchange, Queue
queue = Queue("input.queue", Exchange("default"), "input.key")
app = Celery(broker="amqp://")