Last active
January 2, 2022 18:48
-
-
Save Realiserad/149460d9469e252452ef00d75a50e865 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bs4 import BeautifulSoup | |
| import pickle | |
| from urllib.request import urlopen | |
| import json | |
| from urllib.parse import quote_plus | |
| import sys | |
| import os | |
| from selenium import webdriver | |
| from selenium.webdriver.firefox.options import Options | |
| template = """Ny annons på Blocket. | |
| Titel: {title} | |
| Länk: https://blocket.se{link}""" | |
| storage = os.path.join(sys.path[0], 'ads') | |
| try: | |
| ads = pickle.load(open(storage, 'rb')) | |
| except: | |
| ads = set() | |
| o = Options() | |
| o.headless = True | |
| driver = webdriver.Firefox(options = o) | |
| page = driver.get('https://www.blocket.se/annonser/hela_sverige?q=Daytona%20675') | |
| soup = BeautifulSoup(driver.page_source, 'html.parser') | |
| for tag in soup.find_all('div'): | |
| if tag.has_attr('aria-label') and tag.find('a', href=True) is not None: | |
| a = tag.find('a', href=True) | |
| message = template.format(title = tag['aria-label'], link = a['href']) | |
| if message not in ads: | |
| libsignal = urlopen("https://signal.stormhub.org/v1/send?recipient=&message={0}&apikey=".format(quote_plus(message))) | |
| response = json.loads(libsignal.read()) | |
| print('-> ' + json.dumps(response, indent = 4, sort_keys = True)) | |
| ads.add(message) | |
| driver.close() | |
| pickle.dump(ads, open(storage, 'wb')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment