higherupanddown / tg_bot_loader Goto Github PK
View Code? Open in Web Editor NEWFlibustabot
Flibustabot
from os import link, name, path, listdir
import os
import re
import json
books_dict = {}
links=['']*3
#возврат списка книг
def parcing(boockname, id):
frsymbl=boockname[0]
name=os.listdir(frsymbl)
name=re.search(boockname, name, re.I)
with open(f'bigdict.json', "r", encoding='utf-8') as f:
bigdict=json.loads(f.read())
book=list(bigdict.keys())
n=0
listofbooks=[]
boockpath=[]
for i in list(bigdict.keys()):
if i.find(boockname)!=1:
listofbooks[n]=i
boockpath[n]=bigdict[i]
n+=1
if boockpath != None:
listbooks = list(books_dict.keys())
book="\n".join(str(x) for x in listbooks)
if len(book)>=4096:
book=book[:4096]
book=book.rpartition('\n')[0]
with open(f'dicts/books{id}.json', 'w', encoding='utf-8') as file:
json.dump(books_dict, file, indent=4, ensure_ascii=False)
# i = 0
# for item in book:
# i=i+1
# print(f'{i} {item}')
else:
book='404'
return book
#возврат ссылки на выбранную книгу
def booknumber(number, id):
with open(f'dicts/books{id}.json', 'r', encoding='utf-8') as f:
books_dict=json.loads(f.read())
book=list(books_dict.keys())
i = int(number)-1
if i < len(list(books_dict.values())):
url = list(books_dict.values())[i]
books_dict.update({'fb2':url+'/fb2'})
books_dict.update({'epub':url+'/epub'})
books_dict.update({'mobi':url+'/mobi'})
books_dict.update({'i':i})
number_of_form='Выберете формат для скачивания: \n1. fb2 \n2. epub \n3. mobi'
with open(f'dicts/books{id}.json', "w", encoding='utf-8') as write_file:
json.dump(books_dict, write_file)
else:
number_of_form='Цифры, Мейсон!'
return number_of_form
#/:*?«<>|
#возврат файла (названия)
def filename(number, id):
with open(f'dicts/books{id}.json', 'r', encoding='utf-8') as f:
books_dict=json.loads(f.read())
number = int(number)
book=list(books_dict.keys())
if number == 1:
path='books/' + str(id) + '.fb2'
links = books_dict.get('fb2')
elif number == 2:
path='books/' + str(id) + '.epub'
links = books_dict.get('epub')
elif number == 3:
path='books/' + str(id) + '.mobi'
links = books_dict.get('mobi')
f=open(f'{path}', 'wb')
f.write(content.content)
f.close
return path
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.