Skip to content

Commit 549b2e9

Browse files
Merge pull request #2468 from avinashkranjan/deepsource-transform-5aea34ec
format code with autopep8
2 parents 44fbf73 + 00ddee1 commit 549b2e9

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

Telegram_Book_Bot/book.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
def link_to_get(link):
99
"""This function will get the url of the image & book download direct link using the given link for book download"""
1010
response = requests.get(link)
11-
th_html = bs(response.text , "html.parser")
12-
td_all = th_html.find_all("td" ,id ="info")
11+
th_html = bs(response.text, "html.parser")
12+
td_all = th_html.find_all("td", id="info")
1313
td_all = td_all[0]
1414
td_a = td_all.find_all("a")
1515
link_href = td_a[1].get("href")
16-
img_link_td = td_all.find("img" ,alt="cover")
16+
img_link_td = td_all.find("img", alt="cover")
1717
img_link_src = img_link_td.get("src")
1818
img_link = f"http://library.lol{img_link_src}"
1919
return [link_href, img_link]
2020

2121

22-
2322
def book_get(name, mainres=25, results=5):
2423
"""This function returns the list of books for the given name
2524
@@ -47,20 +46,20 @@ def book_get(name, mainres=25, results=5):
4746
# getting request and response
4847
url = f"http://libgen.is/search.php?req={name}&lg_topic=libgen&open=0&view=simple&res={mainres}&phrase=1&column=def"
4948
response = requests.get(url)
50-
bs_html = bs(response.text , "html.parser")
49+
bs_html = bs(response.text, "html.parser")
5150

5251
if "Search string must contain minimum 3 characters.." in bs_html.body:
5352
return "Error: Title Too Short"
54-
53+
5554
# scraping the site for response
5655
table = bs_html.find_all("table")
5756
table = table[2]
5857
table_rows = table.find_all("tr")
5958
a = len(table_rows)
6059
table_rows.pop(0)
61-
if a > 1 :
60+
if a > 1:
6261
counter = 0
63-
for i in table_rows :
62+
for i in table_rows:
6463
if counter <= results:
6564
# make book list
6665
book_lst = []
@@ -76,7 +75,7 @@ def book_get(name, mainres=25, results=5):
7675
publisher = "unknown"
7776
# getting link to book
7877
link_row = table_datas[9]
79-
a = link_row.find("a" , href = True)
78+
a = link_row.find("a", href=True)
8079
link = a.get("href")
8180
# getting image url & direct book download link
8281
link_all = link_to_get(link)
@@ -101,20 +100,20 @@ def book_get(name, mainres=25, results=5):
101100
book_lst.append(link_all[1])
102101
book_lst.append(language)
103102
Books.append(book_lst)
104-
counter+=1
105-
if len(Books) >=1 :
103+
counter += 1
104+
if len(Books) >= 1:
106105
return Books
107-
else :
106+
else:
108107
return "Error: no results found"
109108
else:
110109
return "Error: no results found"
111-
112110

113111

114112
if __name__ == "__main__":
115-
a = book_get("Python",25,5)
113+
a = book_get("Python", 25, 5)
116114
if "Error" not in a:
117-
for i in a :
118-
print(f"\n\nName : {i[0]}\nAuthor : {i[1]}\nPublisher : {i[2]}\nSize : {i[3]}\nFormat : {i[4]}\nLink : {i[5]}\nImage : {i[6]}\n\n")
115+
for i in a:
116+
print(
117+
f"\n\nName : {i[0]}\nAuthor : {i[1]}\nPublisher : {i[2]}\nSize : {i[3]}\nFormat : {i[4]}\nLink : {i[5]}\nImage : {i[6]}\n\n")
119118
else:
120-
print(a)
119+
print(a)

Telegram_Book_Bot/main.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,47 @@
1515
# ////////////////
1616
# BOT COMMANDS............\\\
1717

18+
1819
@bot.message_handler(commands=["start"])
1920
def starting(message):
2021
text = f"I am a simple book bot.\nI will help you to download books of your own choice\nOur syntax is easy just send\n/book<space><book name>\nWithout without bracket sign.\nEXAMPLE : /book abc\n\nSend /help to get help"
21-
bot.reply_to(message , text)
22+
bot.reply_to(message, text)
2223

2324

2425
@bot.message_handler(commands=["help"])
2526
def help(message):
2627
text = f"Commands:\n1. /book <book_name>"
27-
bot.reply_to(message , text)
28+
bot.reply_to(message, text)
2829

2930

30-
@bot.message_handler(commands = ["book"])
31+
@bot.message_handler(commands=["book"])
3132
def books_get(message):
3233
id = message.from_user.id
3334
given_name = message.text[6:]
34-
messageId = bot.reply_to(message , "Please wait...").message_id
35+
messageId = bot.reply_to(message, "Please wait...").message_id
3536
chatId = message.chat.id
3637
data = book_get(given_name)
3738
if data == "Error: emoji":
38-
bot.reply_to(message , "Error: emoji\nPlease do not use Emojis😂")
39+
bot.reply_to(message, "Error: emoji\nPlease do not use Emojis😂")
3940
elif data == "Error: no results found":
40-
bot.reply_to(message , "Error: no results found\nPlease try for another book.")
41+
bot.reply_to(
42+
message, "Error: no results found\nPlease try for another book.")
4143
elif data == "Error: enter name":
42-
bot.reply_to(message , "Error: enter name\nPlease provide the name of book you are looking for")
44+
bot.reply_to(
45+
message, "Error: enter name\nPlease provide the name of book you are looking for")
4346
elif data == "Error: Title Too Short":
44-
bot.reply_to(message , "Error: Title Too Short\nPlease provide full title for better results")
47+
bot.reply_to(
48+
message, "Error: Title Too Short\nPlease provide full title for better results")
4549
else:
4650
counter = 0
4751
bot.delete_message(chatId, messageId)
4852
for i in data:
4953
if counter <= results:
5054
dn = f"[DOWNLOAD NOW]({i[5]})"
5155
caption_all = f"*Name* : {i[0]}\n*Author* : {i[1]}\n*Size* : {i[3]}\n*Format* : {i[4]}\n{dn}"
52-
bot.send_photo(id ,i[6] , caption = caption_all ,parse_mode ="Markdown" )
53-
counter+=1
56+
bot.send_photo(id, i[6], caption=caption_all,
57+
parse_mode="Markdown")
58+
counter += 1
5459

5560

5661
while True:
@@ -62,4 +67,4 @@ def books_get(message):
6267
continue
6368

6469

65-
# ////////////////
70+
# ////////////////

0 commit comments

Comments
 (0)