diff --git a/peer_instances.py b/peer_instances.py deleted file mode 100644 index 97abb93..0000000 --- a/peer_instances.py +++ /dev/null @@ -1,77 +0,0 @@ -# import libraries -from selenium import webdriver -from selenium.webdriver.common.keys import Keys -import os -import time -import datetime -from pprint import pprint -import requests -import multiprocessing -from mastodon import Mastodon -from pprint import pprint - -mastodon = Mastodon( - access_token = '9cebc1c5ff071137342c761224d2ce1ce3740b0243c151dd4218353f65c65ca1', - api_base_url = 'https://post.lurk.org' -) - -peers = mastodon.instance_peers() - -today = datetime.date.today() -text_file = open("results.txt", "a+") -text_file.write("Data collected on : "+str(today)+"\n"+"\n") - - -for n, peer in enumerate(peers): - if n < 9: - time.sleep(0.5) - # get the url from the terminal - # url ("Enter instance.social url (include https:// ): ") - url = "https://"+(str(peer)) - print(peer) - - # Tell Selenium to open a new Firefox session - # and specify the path to the driver - driver = webdriver.Firefox(executable_path=os.path.dirname(os.path.realpath(__file__)) + '/geckodriver') - - # Implicit wait tells Selenium how long it should wait before it throws an exception - driver.implicitly_wait(10) - driver.get(url) - time.sleep(3) - - print ('Instance:', "\n", peer) - text_file.write("Instance: "+"\n"+(peer)+"\n") - - try: - description = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[3]/div[2]/div') - print ('Description:') - print(description.text) - text_file.write("Description: "+"\n"+description.text+"\n"+"\n") - time.sleep(1) - - try: - # get the image source - img = driver.find_element_by_css_selector('.landing-page__hero > img:nth-child(1)') - src = img.get_attribute('src') - # download the image - Picture_request = requests.get(src) - if Picture_request.status_code == 200: - with open("{}.jpg".format(peer), 'wb') as f: - f.write(Picture_request.content) - print("Printed Image") - - except: - print("Impossible to print image") - - except: - print("Impossible to check instance") - - time.sleep(0.5) - - # close new tab - driver.close() - print("Closing Window") - -text_file.close() -# close the browser -driver.close()