You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

53 lines
1.6 KiB

"""Provides the `post_HFR` function that posts messages to HFR.
You should get those ready:
user (str): username
user_hash (str): hashlib.md5(<plaintext_password>.encode()).hexdigest()
posturl (str): the post URL you are responding to (any post in the
topic will do)
newpost (str): BBcode of the new post that's being posted
Beware of throttling/anti-flood limitations.
"""
import urllib.parse
import requests
from bs4 import BeautifulSoup
BASE = 'https://forum.hardware.fr'
POST = '/bddpost.php'
def post_HFR(user, user_hash, posturl, newpost):
"""Based on inputs, posts to HFR. Returns the resulting `requests` object.
"""
# Cookie preparation. 3 Ss for md_passs, yes.
cookie = {'md_passs': user_hash,
'md_user': user}
# Create HFR session
HFR = requests.Session()
HFR.cookies.update(cookie)
# Retrieve page, we'll need the hash_check from it
req = HFR.get(posturl)
soup = BeautifulSoup(req.text, 'html.parser')
# Parse post URL, we'll need to extract a bunch of values from it
parsedURL = urllib.parse.parse_qs(posturl)
# Prepare payload
payload = {'hash_check': soup.find('input',
{'name': 'hash_check'})['value'],
'post': parsedURL['post'][0],
'cat': parsedURL['cat'][0],
'verifrequet': 1100,
'sujet': soup.find('input', {'name': 'sujet'})['value'],
'content_form': newpost,
'pseudo': user,
'signature': 1}
# Post payload
post_req = HFR.post(BASE+POST, data=payload)
return post_req