Skip to content

Commit 79a81ab

Browse files
committed
Removed useless print and reordered code
1 parent 33c94c2 commit 79a81ab

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

main.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def index(message):
7474
categoryName = ''.join(categoryName[0])
7575
category = "https://raw.githubusercontent.com/EbookFoundation/free-programming-books/main/" + categoryName
7676

77-
r = requests.get(category)
78-
f = r.text
77+
f = requests.get(category)
78+
f = f.text
7979
f = f.splitlines()
8080

8181
check = False
@@ -103,15 +103,15 @@ def index(message):
103103

104104
@bot.message_handler(commands=['category'])
105105
def select_category(message):
106-
r = requests.get("https://raw.githubusercontent.com/EbookFoundation/free-programming-books/main/README.md")
107-
categoryFile = r.text
108-
categoryFile = categoryFile.replace("####", "###")
109-
categoryFile = categoryFile.splitlines()
106+
f = requests.get("https://raw.githubusercontent.com/EbookFoundation/free-programming-books/main/README.md")
107+
f = f.text
108+
f = f.replace("####", "###")
109+
f = f.splitlines()
110110

111111
check = False
112112
text = ""
113113

114-
for line in categoryFile:
114+
for line in f:
115115
if line == "### Books":
116116
check = True
117117
elif line == "### Translations":
@@ -126,8 +126,6 @@ def select_category(message):
126126
tmp = re.findall(r'[^\(]+\.md(?=\))', line)
127127
text += "`" + tmp[0] + "`\n"
128128

129-
print(text)
130-
131129
keyboard=types.InlineKeyboardMarkup(row_width=1)
132130
cancelButton=types.InlineKeyboardButton(text="Cancel", callback_data="cancel")
133131
keyboard.add(cancelButton)
@@ -145,22 +143,20 @@ def select_category(message):
145143
log(message, text)
146144

147145
def change_category(message):
148-
r = requests.get("https://raw.githubusercontent.com/EbookFoundation/free-programming-books/main/README.md")
149-
categoryFile = r.text
150-
categoryFile = categoryFile.splitlines()
146+
f = requests.get("https://raw.githubusercontent.com/EbookFoundation/free-programming-books/main/README.md")
147+
f = f.text
148+
f = f.splitlines()
151149

152150
text = "Not correct"
153151

154-
for line in categoryFile:
152+
for line in f:
155153
if re.findall(r'[^\(]+\.md(?=\))', line):
156154
tmp = re.findall(r'[^\(]+\.md(?=\))', line)
157155
tmp = "" + str(tmp[0])
158156
if tmp == message.text:
159157
cursor.execute('UPDATE fpb SET choice=%s WHERE id=%s;', (message.text, message.chat.id,))
160158
conn.commit()
161159
text = "Updated"
162-
print(text)
163-
164160

165161
bot.reply_to(
166162
message,
@@ -194,8 +190,8 @@ def print_resource(message):
194190
category = ''.join(category[0])
195191
category = "https://raw.githubusercontent.com/EbookFoundation/free-programming-books/main/" + category
196192

197-
r = requests.get(category)
198-
f = r.text
193+
f = requests.get(category)
194+
f = f.text
199195
f = f.replace("####", "###")
200196
f = f.splitlines()
201197
t = message.json

0 commit comments

Comments
 (0)