mirror of
https://github.com/Araon/Meido.git
synced 2025-02-20 11:13:20 +08:00
added dummey config and added mongodb posting
This commit is contained in:
parent
d6f9051179
commit
6aa2dd969d
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,4 +2,4 @@ botConfig.json
|
||||
*.session
|
||||
agentConfig.json
|
||||
images
|
||||
test.mp4
|
||||
*.mp4
|
||||
|
56
bot/bot.py
56
bot/bot.py
@ -1,16 +1,13 @@
|
||||
from cgitb import text
|
||||
import logging
|
||||
import json
|
||||
from operator import truediv
|
||||
from time import time
|
||||
from datetime import datetime
|
||||
from turtle import up
|
||||
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
|
||||
from telegram.update import Update
|
||||
from botUtils import showhelp,parse_search_query,getalltsfiles,getAnimelink
|
||||
from database import getData, postData
|
||||
from botUtils import showhelp,parse_search_query,getalltsfiles
|
||||
from database import getData, postData, updateData
|
||||
import subprocess
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
|
||||
|
||||
#enabling Logging
|
||||
@ -32,39 +29,42 @@ def help(update,context):
|
||||
update.message.reply_text(text)
|
||||
|
||||
|
||||
def search(update, context):
|
||||
logger.info('Search function is called!')
|
||||
link = getAnimelink(update.message.text)
|
||||
|
||||
|
||||
|
||||
def get(update, context):
|
||||
def getanime(update, context):
|
||||
logger.info('download function is called!')
|
||||
chat_id = update.message.chat_id
|
||||
rawUserInput = update.message.text
|
||||
userInput = rawUserInput[:]
|
||||
userInput = rawUserInput[10:]
|
||||
|
||||
if userInput and not userInput == " ":
|
||||
userdata = parse_search_query(userInput)
|
||||
update.message.reply_text(f"Checking Internal Db\nAnime: {userdata.get('series_name')}\nSeason: {userdata.get('season_id')}\nEpisode: {userdata.get('episode_id')}")
|
||||
anime_name = getData(userdata)
|
||||
logger.info('search_in_mongodb:"%s"', userdata)
|
||||
search_in_mongodb = userdata.pop('season_id')
|
||||
anime_name = getData(search_in_mongodb)
|
||||
if not anime_name:
|
||||
logger.info('Got data from mongoDB')
|
||||
logger.info(anime_name)
|
||||
update_times_queried = updateData(anime_name)
|
||||
download_status = subprocess.check_call("python downloaderService/main.py "+'"'+userdata.get('series_name')+'"'+' '+ userdata.get('episode_id') , shell=True)
|
||||
else:
|
||||
try:
|
||||
context.bot.send_video(chat_id,anime_name.get("file_id"),supports_streaming=True,timeout=120)
|
||||
except:
|
||||
update.message.reply_text("anime_name is empty and anime_name has no file_id")
|
||||
|
||||
else:
|
||||
update.message.reply_text("Please refer to /help")
|
||||
|
||||
update.message.reply_text(f"{userdata.get('series_name')} - {userdata.get('episode_id')} almost done downloading on the server side!")
|
||||
filepath = getalltsfiles()
|
||||
upload_status = subprocess.check_call("python uploaderService/main.py " +'"'+filepath+'"'+ ' ' + str(chat_id) + ' ' + (userdata.get('series_name')+str(userdata.get('episode_id'))), shell=True)
|
||||
upload_status = subprocess.check_call("python uploaderService/main.py " +'"'+filepath+'"'+ ' ' + str(chat_id) + ' ' + (userdata.get('series_name')+'-'+str(userdata.get('episode_id'))), shell=True)
|
||||
|
||||
|
||||
def error(update, context):
|
||||
"""Log Errors caused by Updates."""
|
||||
logger.warning('Update "%s" caused error "%s"', update, context.error)
|
||||
logger.warning('Update "%s" caused error "%s" and "%s"', update, context.error, context )
|
||||
update.message.reply_text("Something has went wrong!, Please retry :)")
|
||||
|
||||
|
||||
def check_document(update, context):
|
||||
'''
|
||||
This function is important as this checks for all the files uploaded to the telegram server
|
||||
@ -76,7 +76,22 @@ def check_document(update, context):
|
||||
if user_id == configdata.get('agent_user_id'):
|
||||
file_id = update.message.video.file_id
|
||||
caption = update.message.caption
|
||||
object_id = caption.split(":")[1]
|
||||
end_user_chat_id = caption.split(":")[0]
|
||||
series_name = object_id.split("-")[0]
|
||||
episode_id = object_id.split("-")[1]
|
||||
|
||||
data2post = {
|
||||
"series_name":series_name,
|
||||
"episode_id":episode_id,
|
||||
"file_id":file_id,
|
||||
"times_queried":0,
|
||||
"date_added":datetime.now()
|
||||
}
|
||||
logger.info('Got Posting data to mongoDB')
|
||||
logger.info(data2post)
|
||||
post_data_to_mongo = postData(data2post)
|
||||
logger.info(post_data_to_mongo)
|
||||
#Keep in mind here i have to parse the chat_id from the caption above
|
||||
context.bot.send_video(end_user_chat_id,file_id,supports_streaming=True,timeout=120)
|
||||
|
||||
@ -105,8 +120,7 @@ def main():
|
||||
# added handlers
|
||||
dp.add_handler(CommandHandler("start", start))
|
||||
dp.add_handler(CommandHandler("help", help))
|
||||
dp.add_handler(CommandHandler("search", search))
|
||||
dp.add_handler(CommandHandler("get", get))
|
||||
dp.add_handler(CommandHandler("getanime", getanime))
|
||||
dp.add_handler(MessageHandler(Filters.text, debug_message))
|
||||
dp.add_handler(MessageHandler(Filters.video, check_document))
|
||||
|
||||
|
@ -9,10 +9,13 @@ example - /search Death Note
|
||||
|
||||
'''
|
||||
import os
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
|
||||
def showhelp():
|
||||
helpText = "Here are the following bot commands\n\n/get - will download the anime episode you wanted(make sure you seperate the name and the season and ep with comma)\nexample - /get Death note, 1, 3\n\n/search(still in development) - will provide deatails about an anime\nexample - /search Death Note"
|
||||
helpText = "Here are the following bot commands\n \
|
||||
\n/getanime - will download the anime episode you wanted(make sure you seperate the name and the season and ep with comma) \
|
||||
\nexample - /getanime Death note, 1, 3\n\n/search(still in development) \
|
||||
- will provide deatails about an anime\nexample - /search Death Note"
|
||||
return helpText
|
||||
|
||||
def parse_search_query(raw_input):
|
||||
@ -40,21 +43,10 @@ def getalltsfiles():
|
||||
for file in files:
|
||||
if (file.split(".")[-1].lower() == 'mp4'):
|
||||
mp4FilePath = os.path.join(root, os.path.splitext(file)[0] + ".mp4")
|
||||
# seriously mate, i'm tired and this might be the worst piece of hack i've done in my life
|
||||
# yet!
|
||||
mp4FilePath = mp4FilePath.replace("\\","/")
|
||||
mp4FilePath = mp4FilePath.replace("\\","/") # seriously mate, i'm tired and this might be the worst piece of hack i've done in my life, yet!
|
||||
return mp4FilePath
|
||||
|
||||
|
||||
def getAnimelink(search_query):
|
||||
userInput = search_query[8:]
|
||||
if userInput and not userInput == " ":
|
||||
userdata = parse_search_query(userInput)
|
||||
|
||||
import pdb
|
||||
pdb.set_trace()
|
||||
#return raw_search_data
|
||||
|
||||
|
||||
# python uploaderService/main.py ./Naruto/E04.mp4 5023977571 naruto4
|
||||
|
||||
|
4
bot/config/exampleConfig.json
Normal file
4
bot/config/exampleConfig.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"bot_token": "BOT_TOKEN",
|
||||
"agent_user_id": 123
|
||||
}
|
@ -1,7 +1,4 @@
|
||||
from pymongo import MongoClient
|
||||
import datetime
|
||||
import json
|
||||
from botUtils import parse_search_query
|
||||
|
||||
client = MongoClient('mongodb://localhost:27017/')
|
||||
|
||||
@ -10,7 +7,6 @@ db = client["animeDatabase"]
|
||||
#collection
|
||||
col = db["animeDatabase"]
|
||||
|
||||
|
||||
'''
|
||||
* DB Models
|
||||
* animeDatabase
|
||||
@ -28,9 +24,17 @@ def postData(data):
|
||||
post_id = col.insert_one(data).inserted_id
|
||||
return post_id
|
||||
except:
|
||||
return {}
|
||||
return 0
|
||||
|
||||
def getData(data):
|
||||
anime_data = col.find_one(filter=data)
|
||||
anime_data = col.find_one(filter=data) #{"serise_name":"anime_name", "episode_id":2 }
|
||||
return anime_data
|
||||
|
||||
def updateData(data):
|
||||
try:
|
||||
update_id = col.update_one({"series_name":data.get('series_name') , "episode_id": data.get('episode_id')},{'$inc': {'times_queried':1}})
|
||||
return update_id
|
||||
except:
|
||||
return 0
|
||||
|
||||
#result = db.test.update_one({'x': 1}, {'$inc': {'x': 3}})
|
7
uploaderService/config/Example_agentConfig.json
Normal file
7
uploaderService/config/Example_agentConfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"entity": "entity",
|
||||
"api_id": "api_id",
|
||||
"api_hash": "api_hash",
|
||||
"bot_name": "bot_name"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user