Giter VIP home page Giter VIP logo

tg_bot_loader's People

Stargazers

 avatar

Watchers

 avatar

tg_bot_loader's Issues

test

from os import link, name, path, listdir
import os
import re
import json

print('Введите название книги, серию или автора')

text = input()

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.