kertser commited on
Commit
dd2dd36
1 Parent(s): e9bab1f

Upload WarOnline_Chat.py

Browse files
Files changed (1) hide show
  1. WarOnline_Chat.py +64 -0
WarOnline_Chat.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This is an automation of Bot to post to a specific thread in the forum.
2
+
3
+ import requests
4
+ from bs4 import BeautifulSoup
5
+
6
+ # Define the login URL and the thread URL
7
+ login_url = 'https://waronline.org/fora/index.php?login/login'
8
+ thread_url = 'https://waronline.org/fora/index.php?threads/Творчество-роботов-нейросети-и-т-п.17617/'
9
+ #thread_url = 'https://waronline.org/fora/index.php?threads/%D0%A2%D0%B2%D0%BE%D1%80%D1%87%D0%B5%D1%81%D1%82%D0%B2%D0%BE-%D1%80%D0%BE%D0%B1%D0%BE%D1%82%D0%BE%D0%B2-%D0%BD%D0%B5%D0%B9%D1%80%D0%BE%D1%81%D0%B5%D1%82%D0%B8-%D0%B8-%D1%82-%D0%BF.17617/'
10
+
11
+ # Define the login credentials
12
+ username = 'WarBot'
13
+ password = 'naP2tion'
14
+
15
+ # Start a session to persist the login cookie across requests
16
+ session = requests.Session()
17
+
18
+ # Retrieve the login page HTML to get the CSRF token
19
+ login_page_response = session.get(login_url)
20
+ soup = BeautifulSoup(login_page_response.text, 'html.parser')
21
+ csrf_token = soup.find('input', {'name': '_xfToken'})['value']
22
+
23
+ # Login to the website
24
+ login_data = {
25
+ 'login': username,
26
+ 'password': password,
27
+ 'remember': '1',
28
+ '_xfRedirect': thread_url,
29
+ '_xfToken': csrf_token
30
+ }
31
+ response = session.post(login_url, data=login_data)
32
+
33
+ # Check if the login was successful
34
+ if 'Invalid login' in response.text:
35
+ print('Login failed!')
36
+ exit()
37
+
38
+ # Retrieve the thread page HTML
39
+ response = session.get(thread_url)
40
+
41
+ # Parse the HTML with BeautifulSoup
42
+ soup = BeautifulSoup(response.text, 'html.parser')
43
+
44
+ # Extract the _xfToken value from the hidden form field
45
+ xf_token = soup.find('input', {'name': '_xfToken'}).get('value')
46
+
47
+ # Post a message to the thread
48
+ post_data = {
49
+ 'message_html': 'Hello world!', # Replace with your message
50
+ 'last_date': '', # Leave empty for a new post
51
+ 'watch_thread': '1', # Subscribe to the thread (optional)
52
+ '_xfToken': xf_token, # Retrieve the token from the page HTML '1676385710,1cdf871cad6915a8f95aa9ddb0e03cc9'
53
+ '_xfRequestUri': thread_url, # Retrieve from the page HTML
54
+ '_xfWithData': '1', # Required for some XenForo versions
55
+ '_xfResponseType': 'json' # Receive the response in JSON format
56
+ }
57
+ response = session.post(thread_url, data=post_data)
58
+
59
+ # Check if the post was successful
60
+ if not response.ok:
61
+ print('Post failed!')
62
+ exit()
63
+
64
+ print('Post submitted successfully.')