move feeds to ptb
This commit is contained in:
@@ -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:
|
||||
|
@@ -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']:
|
||||
|
@@ -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
|
||||
|
@@ -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 = ''
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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:
|
||||
|
@@ -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:
|
||||
|
@@ -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:
|
||||
|
@@ -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:
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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:
|
||||
|
Reference in New Issue
Block a user