Skip to content

Instantly share code, notes, and snippets.

@khllkcm
Last active May 29, 2019 18:24
Show Gist options
  • Save khllkcm/a3e8f97adf7f7aec3322f9bb6ebea4e5 to your computer and use it in GitHub Desktop.
Save khllkcm/a3e8f97adf7f7aec3322f9bb6ebea4e5 to your computer and use it in GitHub Desktop.
Scrap the latest Forum Libre url from r/France and serve it.
import requests
import re
import os
import urllib.parse
headers = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"}
response = requests.get("https://reddit.com/r/france/search?sort=new&q=flair%3AForum%2BLibre&restrict_sr=on&t=day", headers=headers)
result = re.search(
r"https://www.reddit.com/r/france/comments/?.{6}/forum_.*?libre.*?20.+?/",
response.text
)
if result:
link = result.group()
os.system(f'echo "Redirect /FL/ {link[:6]+urllib.parse.quote(link[6:])}?sort=new" > /srv/kacem.xyz/.htaccess')
else:
os.system("rm /srv/kacem.xyz/.htaccess")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment