mirror of
https://github.com/house-of-vanity/gaspar.git
synced 2025-07-06 18:24:07 +00:00
asd
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__/
|
Binary file not shown.
Binary file not shown.
BIN
data.sqlite
BIN
data.sqlite
Binary file not shown.
11
database.py
11
database.py
@ -215,7 +215,7 @@ class DataBase:
|
||||
'tor_status',
|
||||
'seeders',
|
||||
'topic_title',
|
||||
'seeder_last_seen'
|
||||
'seeder_last_seen',
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"""
|
||||
self.execute(sql, attrs)
|
||||
|
||||
@ -250,7 +250,7 @@ class DataBase:
|
||||
tor_data["id"],
|
||||
))
|
||||
|
||||
def save_tor(self, tor_data, chat_instance):
|
||||
def save_tor(self, tor_data):
|
||||
sql = """INSERT OR IGNORE INTO torrents(
|
||||
'id',
|
||||
'info_hash',
|
||||
@ -261,9 +261,8 @@ class DataBase:
|
||||
'tor_status',
|
||||
'seeders',
|
||||
'topic_title',
|
||||
'seeder_last_seen',
|
||||
'user_id'
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"""
|
||||
'seeder_last_seen'
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"""
|
||||
self.execute(sql, (
|
||||
tor_data["id"],
|
||||
tor_data["info_hash"],
|
||||
@ -275,8 +274,8 @@ class DataBase:
|
||||
tor_data["seeders"],
|
||||
tor_data["topic_title"],
|
||||
tor_data["seeder_last_seen"],
|
||||
chat_instance['id'],
|
||||
))
|
||||
def save_user(self, chat_instance):
|
||||
sql = """INSERT OR IGNORE INTO users(
|
||||
'id',
|
||||
'username',
|
||||
|
16
main.py
16
main.py
@ -1,10 +1,11 @@
|
||||
import os
|
||||
import logging
|
||||
from urllib import parse
|
||||
from rutracker import Torrent
|
||||
from datetime import datetime
|
||||
from database import DataBase
|
||||
from telegram import *
|
||||
from telegram.ext import Updater, MessageHandler, CommandHandler, filters
|
||||
from urllib import parse
|
||||
import logging
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
@ -19,6 +20,7 @@ def sizeof_fmt(num, suffix='B'):
|
||||
return "%.1f%s%s" % (num, 'Yi', suffix)
|
||||
|
||||
def main():
|
||||
token = os.environ.get('TG_TOKEN')
|
||||
"""Run bot."""
|
||||
|
||||
def add(update, context):
|
||||
@ -32,8 +34,12 @@ def main():
|
||||
else:
|
||||
update.message.reply_text("Send me a URL to rutracker.org topic.")
|
||||
return
|
||||
log.debug(update.message.chat)
|
||||
torrent = Torrent(tor_id, update.message.chat)
|
||||
torrent = Torrent(tor_id)
|
||||
torrent.db.save_tor(torrent.meta)
|
||||
torrent.db.save_user(update.message.chat)
|
||||
torrent.db.save_alert(update.message.chat['id'], torrent.meta['id'])
|
||||
# log.debug(torrent.is_outdated())
|
||||
# log.debug(torrent.update())
|
||||
reg_time = datetime.utcfromtimestamp(int(torrent.meta['reg_time'])
|
||||
).strftime('%b-%d')
|
||||
msg = f"""{torrent.meta['topic_title']}
|
||||
@ -49,7 +55,7 @@ def main():
|
||||
'Hello {}'.format(update.message.from_user.first_name))
|
||||
|
||||
|
||||
updater = Updater("539189256:AAHqrL6nTmv5g0mGoPQownO0vrNRvhPFq7I", use_context=True)
|
||||
updater = Updater(token, use_context=True)
|
||||
|
||||
updater.dispatcher.add_handler(MessageHandler(filters.Filters.text, add))
|
||||
|
||||
|
@ -6,12 +6,11 @@ import re
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class Torrent:
|
||||
def __init__(self, tor_id, chat_instance):
|
||||
def __init__(self, tor_id):
|
||||
self.db = DataBase("scheme.sql")
|
||||
self.api_url = "http://api.rutracker.org/v1/"
|
||||
self.meta = self.get_tor_topic_data(tor_id)
|
||||
log.debug("Torrent info: %s", self.meta)
|
||||
self.db.save_tor(self.meta, chat_instance)
|
||||
|
||||
def get_tor_topic_data(self, tor_id):
|
||||
data = dict()
|
||||
|
@ -10,7 +10,6 @@ CREATE TABLE IF NOT EXISTS "torrents" (
|
||||
"seeders" TEXT,
|
||||
"topic_title" TEXT,
|
||||
"seeder_last_seen" TEXT,
|
||||
"user_id" TEXT,
|
||||
PRIMARY KEY("id")
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "torrents_history" (
|
||||
@ -24,7 +23,6 @@ CREATE TABLE IF NOT EXISTS "torrents_history" (
|
||||
"tor_status" TEXT,
|
||||
"seeders" TEXT,
|
||||
"topic_title" TEXT,
|
||||
"user_id" TEXT,
|
||||
"seeder_last_seen" TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "users" (
|
||||
@ -33,5 +31,9 @@ CREATE TABLE IF NOT EXISTS "users" (
|
||||
first_name TEXT,
|
||||
last_name TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "alerts" (
|
||||
user_id TEXT,
|
||||
tor_id TEXT
|
||||
);
|
||||
COMMIT;
|
||||
|
||||
|
Reference in New Issue
Block a user