move feeds to ptb

This commit is contained in:
bakatrouble 2021-03-20 16:21:13 +03:00
parent b35d2ca251
commit e72cb9a453
12 changed files with 38 additions and 52 deletions

32
Pipfile.lock generated
View File

@ -85,19 +85,19 @@
},
"boto3": {
"hashes": [
"sha256:31396fcaffdfc0f465b4de76e1ecae53894eb869b000ffa54aa1693a98db3a3c",
"sha256:bf8ced7760f9ef36964ccdba719f334a2ae6ec8a7719c259b198fec56fabad87"
"sha256:0cac2fffc1ba915f7bb5ecee539318532db51f218c928a228fafe3e501e9472e",
"sha256:3306dad87f993703b102a0a70ca19c549b7f41e7f70fa7b4c579735c9f79351d"
],
"index": "pypi",
"version": "==1.17.29"
"version": "==1.17.33"
},
"botocore": {
"hashes": [
"sha256:184b7d26b0669fd65ac8193662376d1267d800e005b69412b57cc82c5ffbe935",
"sha256:5a26ad20662f8e15685889a17c62a2f8804bf02fcdea59f45ad993b261f9caa2"
"sha256:a33e862685259fe22d9790d9c9f3567feda8b824d44d3c62a3617af1133543a4",
"sha256:e355305309699d3aca1e0050fc21d48595b40db046cb0d2491cd57ff5b26920b"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'",
"version": "==1.20.29"
"version": "==1.20.33"
},
"celery": {
"hashes": [
@ -311,11 +311,11 @@
},
"django-timezone-field": {
"hashes": [
"sha256:068dc2c9b11c2230e126f511a515609d46f8cc49278b293e7536be07997fe892",
"sha256:b5b587aabed8db66eb3453691522164915c1aa1b326d8ddeadc8832a8580faeb"
"sha256:897c06e40b619cf5731a30d6c156886a7c64cba3a90364832148da7ef32ccf36",
"sha256:cffac62452d060e365938aa9c9f7b72d70d8b26b9c60243bce227b35abd1b9df"
],
"index": "pypi",
"version": "==4.1.1"
"version": "==4.1.2"
},
"django-yamlfield": {
"hashes": [
@ -789,10 +789,10 @@
},
"s3transfer": {
"hashes": [
"sha256:1e28620e5b444652ed752cf87c7e0cb15b0e578972568c6609f0f18212f259ed",
"sha256:7fdddb4f22275cf1d32129e21f056337fd2a80b6ccef1664528145b72c49e6d2"
"sha256:5d48b1fd2232141a9d5fb279709117aaba506cacea7f86f11bc392f06bfa8fc2",
"sha256:c5dadf598762899d8cfaecf68eba649cd25b0ce93b6c954b156aaa3eed160547"
],
"version": "==0.3.4"
"version": "==0.3.6"
},
"sentry-sdk": {
"hashes": [
@ -825,11 +825,11 @@
},
"soupsieve": {
"hashes": [
"sha256:407fa1e8eb3458d1b5614df51d9651a1180ea5fedf07feb46e45d7e25e6d6cdd",
"sha256:d3a5ea5b350423f47d07639f74475afedad48cf41c0ad7a82ca13a3928af34f6"
"sha256:052774848f448cf19c7e959adf5566904d525f33a3f8b6ba6f6f8f26ec7de0cc",
"sha256:c2c1c2d44f158cdbddab7824a9af8c4f83c76b1e23e049479aa432feb6c4c23b"
],
"markers": "python_version >= '3'",
"version": "==2.2"
"version": "==2.2.1"
},
"sqlparse": {
"hashes": [
@ -964,7 +964,7 @@
"sha256:2f4da4594db7e1e110a944bb1b551fdf4e6c136ad42e4234131391e21eb5b0df",
"sha256:e7b021f7241115872f92f43c6508082facffbd1c048e3c6e2bb9c2a157e28937"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'",
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4.0'",
"version": "==1.26.4"
},
"vine": {

View File

@ -4,9 +4,7 @@ from django.contrib.contenttypes.models import ContentType
from django.core.cache import cache
from django.db import models
from django.utils import timezone
from picklefield import PickledObjectField
from telebot import TeleBot
from yamlfield.fields import YAMLField
from telegram import Bot
from feeds.tasks import execute_feed
@ -61,7 +59,7 @@ class FeedModuleConfig(models.Model):
def content_type(self):
return ContentType.objects.get_for_model(self.__class__)
def execute(self, bot: TeleBot, chat_id, last_id):
def execute(self, bot: Bot, chat_id, last_id):
raise NotImplementedError()
class Meta:

View File

@ -1,5 +1,5 @@
import requests
from telebot import TeleBot
from telegram import Bot
from feeds.models import FeedModuleConfig
@ -7,7 +7,7 @@ from feeds.models import FeedModuleConfig
class DankMemesFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'Dank memes (Reddit)'
def execute(self, bot: TeleBot, chat_id, last_id):
def execute(self, bot: Bot, chat_id, last_id):
posts = requests.get('https://www.reddit.com/r/dankmemes/top.json?sort=top&t=hour',
headers={'User-agent': 'bakatrouble FeedBot 0.1'}).json()
for p in posts['data']['children']:

View File

@ -1,5 +1,5 @@
from django.db import models
from telebot import TeleBot
from telegram import Bot
from feeds.models import FeedModuleConfig
@ -9,6 +9,6 @@ class EchoFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'Echo'
def execute(self, bot: TeleBot, chat_id, last_id):
def execute(self, bot: Bot, chat_id, last_id):
bot.send_message(chat_id, self.message)
yield None

View File

@ -1,8 +1,7 @@
import re
from datetime import datetime
import feedparser
from telebot import TeleBot
from telegram import Bot
from telegram.constants import MAX_CAPTION_LENGTH
from feeds.models import FeedModuleConfig
@ -16,7 +15,7 @@ CAPTION_NEWLINE_RE = re.compile(r'(\w*<p>|</p>\w*){1,2}')
class NerfNowFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'NerfNow.com'
def execute(self, bot: TeleBot, chat_id, last_id):
def execute(self, bot: Bot, chat_id, last_id):
if last_id is None:
last_id = ''

View File

@ -1,5 +1,5 @@
import requests
from telebot import TeleBot
from telegram import Bot
from feeds.models import FeedModuleConfig
@ -7,7 +7,7 @@ from feeds.models import FeedModuleConfig
class ShittyWatercolourFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'Shitty Watercolour (Reddit)'
def execute(self, bot: TeleBot, chat_id, last_id):
def execute(self, bot: Bot, chat_id, last_id):
if last_id is None:
last_id = 0

View File

@ -1,16 +1,12 @@
import json
import os
import re
from tempfile import TemporaryDirectory
import sentry_sdk
from django.db import models
from djconfig import config
from telebot import TeleBot
from telebot.types import InputMediaPhoto, InputMediaVideo
from bs4 import BeautifulSoup
import requests
from PIL import Image
from telegram import Bot
from feeds.models import FeedModuleConfig
@ -20,7 +16,7 @@ class TapasFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'Tapas.io comic'
def execute(self, bot: TeleBot, chat_id, last_id):
def execute(self, bot: Bot, chat_id, last_id):
config._reload_maybe()
if last_id is None:

View File

@ -2,8 +2,7 @@ import sentry_sdk
import twitter
from django.db import models
from djconfig import config
from telebot import TeleBot
from telebot.types import InputMediaPhoto, InputMediaVideo
from telegram import Bot, InputMediaPhoto, InputMediaVideo
from feeds.models import FeedModuleConfig
@ -13,7 +12,7 @@ class TwitterFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'Twitter feed'
def execute(self, bot: TeleBot, chat_id, last_id):
def execute(self, bot: Bot, chat_id, last_id):
config._reload_maybe()
if last_id is None:

View File

@ -1,8 +1,7 @@
import sentry_sdk
from django.db import models
from djconfig import config
from telebot import TeleBot
from telebot.types import InputMediaPhoto
from telegram import Bot, InputMediaPhoto
from vk_api import VkApi
from vk_api.audio import VkAudio
@ -18,7 +17,7 @@ class VKFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'VK feed'
def execute(self, bot: TeleBot, chat_id, last_id):
def execute(self, bot: Bot, chat_id, last_id):
config._reload_maybe()
if last_id is None:

View File

@ -1,13 +1,8 @@
import logging
import os
import tempfile
import requests
import sentry_sdk
from django.db import models
from djconfig import config
from telebot import TeleBot
from telebot.types import InputMediaPhoto
from telegram import Bot
from vk_api import VkApi
from vk_api.audio import VkAudio
@ -21,7 +16,7 @@ class VKMusicFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'VK music'
def execute(self, bot: TeleBot, chat_id, last_id):
def execute(self, bot: Bot, chat_id, last_id):
config._reload_maybe()
if last_id is None:

View File

@ -1,6 +1,6 @@
import requests
from django.db import models
from telebot import TeleBot
from telegram import Bot
from feeds.models import FeedModuleConfig
@ -10,7 +10,7 @@ class WPComicFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'WordPress comic'
def execute(self, bot: TeleBot, chat_id, last_id):
def execute(self, bot: Bot, chat_id, last_id):
if last_id is None:
last_id = 0

View File

@ -4,8 +4,8 @@ import sentry_sdk
from celery_once import QueueOnce
from django.utils import timezone
from django.core.cache import cache
from telebot import TeleBot
from djconfig import config
from telegram import Bot
from config.celery import app
@ -33,7 +33,7 @@ def execute_feed(feed_pk):
with sentry_sdk.configure_scope() as scope:
scope.set_tag('feed', str(feed))
try:
bot = TeleBot(config.feed_bot_token, threaded=False)
bot = Bot(config.feed_bot_token)
print(f'Last ID for "{feed}" = "{feed.last_id}"')
for last_id in feed.config.execute(bot, feed.chat_id, feed.last_id):
if last_id: