kertser commited on
Commit
88a7bf2
1 Parent(s): e6bf96b

Upload WarOnline_Chat.py

Browse files

Updated the "getLastPage" method to faster one.

Files changed (1) hide show
  1. WarOnline_Chat.py +15 -1
WarOnline_Chat.py CHANGED
@@ -71,6 +71,20 @@ def getLastPage(thread_url=config.thread_url):
71
  print('Last page of this thread is '+str(page))
72
  return page
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  def login(username=config.username, password=config.password, thread_url=config.thread_url):
75
  # Log-In to the forum and redirect to thread
76
 
@@ -228,7 +242,7 @@ def WarOnlineBot():
228
  login(username=config.username, password=config.password, thread_url=config.thread_url)
229
 
230
  lookUpPages = 5 # How many pages back to look in the thread
231
- startingPage = getLastPage(thread_url=config.thread_url) - lookUpPages
232
  if startingPage < 1:
233
  startingPage = 1 # Starting page cannot be less than 1
234
 
 
71
  print('Last page of this thread is '+str(page))
72
  return page
73
 
74
+ def getLastPage2(thread_url=config.thread_url):
75
+ # Returns the number of the last page in faster manner
76
+ print('looking for the last page of the thread')
77
+ response = requests.get(thread_url)
78
+ if response.status_code == 200:
79
+ html_content = response.content
80
+ # Parse the HTML content using BeautifulSoup
81
+ soup = BeautifulSoup(html_content, 'html.parser')
82
+ # Find last page number
83
+ data = soup.find_all('li', {'class': 'pageNav-page'})[-1]
84
+ page = int(data.getText())
85
+ print('Last page of this thread is ' + str(page))
86
+ return page
87
+
88
  def login(username=config.username, password=config.password, thread_url=config.thread_url):
89
  # Log-In to the forum and redirect to thread
90
 
 
242
  login(username=config.username, password=config.password, thread_url=config.thread_url)
243
 
244
  lookUpPages = 5 # How many pages back to look in the thread
245
+ startingPage = getLastPage2(thread_url=config.thread_url) - lookUpPages
246
  if startingPage < 1:
247
  startingPage = 1 # Starting page cannot be less than 1
248