def fetch_identity(self): URL = "https://randomuser.me/api/" try: request = requests.get(URL) res = request.json() except json.decoder.JSONDecodeError: print_error("Problème de call API génération de profil. Pause de 3 secondes...") time.sleep(3) request = requests.get(URL) res = request.json() # Evite les prénoms et noms qui utilise des caractères non ascii while len(res["results"][0]["name"]['first'].encode('ascii', 'ignore').decode('utf-8')) == 0 or \ len(res["results"][0]["name"]['last'].encode('ascii', 'ignore').decode('utf-8')) == 0: time.sleep(1) request = requests.get(URL) res = request.json() firstname = res["results"][0]["name"]['first'] firstname = firstname.encode('ascii', 'ignore').decode('utf-8') lastname = res["results"][0]["name"]['last'] lastname = lastname.encode('ascii', 'ignore').decode('utf-8') hobbies = self.choose_hobbies() website = "https://www.soundcloud.com/" + firstname + "_" + lastname summary = "Bonjour, je m'appelle " + firstname + " " + lastname + ", " + "j'aime tout ce qui est " \ + hobbies[0] + " et " + hobbies[1] + "." if len(firstname) == 0 or len(lastname) == 0: return [] return [firstname, lastname, hobbies, website, summary]
def api_get_user_id(self): url = self.base_url + "/profile" HEADER = { 'custom_auth': "authorization=Token " + self.token } request = requests.get(url, headers=HEADER) return request.json()["user_id"]
def subseeker(subSeekerLink,website): baselink = 'http://www.' + website Session = requests.session() SubLinkPage = Session.get(subSeekerLink) try: SubLink = re.findall('Download : <a href="(.*?)"', SubLinkPage.text)[0] except Exception as error: log.error("subseeker: Failed to find the redirect link on SubtitleSeekers") return None Result= requests.get(SubLink) Result.encoding = 'utf-8' if website == 'podnapisi.net': DownLoadLink = re.findall('form-inline download-form\" action=(.*?)>', Result.text)[0] DownLoadLink = urljoin(baselink, DownLoadLink) if DownLoadLink else None elif website =='subscene.com': DownLoadLink = re.findall('<a href=\"/subtitle/download(.*?)\"', Result.text)[0] DownLoadLink = urljoin(baselink + '/subtitle/download', DownLoadLink) if DownLoadLink else None if not DownLoadLink: log.error('downloadsubs: Could not find the downloadlink %s on %s' % (DownLoadLink, website)) try: SubData = unzip(DownLoadLink) return(SubData) except: log.error('downloadsubs:Problem unzipping file %s from %s.' % (DownLoadLink,website)) return None
def _update_library(plexserverhost, plexserverport, plexserverusername, plexserverpassword, plexservertoken): if not plexserverhost: plexserverhost = autosub.PLEXSERVERHOST if not plexserverport: plexserverport = int(autosub.PLEXSERVERPORT) if not plexserverusername: plexserverusername = autosub.PLEXSERVERUSERNAME if not plexserverpassword: plexserverpassword = autosub.PLEXSERVERPASSWORD if not plexservertoken: plexservertoken = autosub.PLEXSERVERTOKEN #Maintain support for older Plex installations without myPlex if not plexservertoken and not plexserverusername and not plexserverpassword: url = "http://%s:%s/library/sections" % (plexserverhost, plexserverport) try: xml_sections = ET.parse(requests.get(url)) except IOError, e: log.error("plexmediaserver: Error while trying to contact: %s" % e) return False
def __check_connect(self): if self.available == 0: try: r = requests.get('http://' + self.path + '/WebService/ServiceV3.asmx?WSDL', headers={ 'Content-Type': 'application/x-www-form-urlencoded' }) text = r.text if text.find('LoginListeningResponse') != -1: self.available = 1 except: library.fail('fail to connect server: ' + self.path) exit() return
def extractor(day, year= '2018', month='09'): url = "http://data.fixer.io/api/" + year + "-" + month + "-" + day # Only variable day ACCESS_KEY = "8bffd25ad11e370e74c1386a39d8192d" access_key = "?access_key=" + ACCESS_KEY currency = "GBP,USD" # More currency conversion rate can be added; Check: Show symbols = "&symbols=" + currency url += access_key + symbols # Url form ### load and save ### response = requests.get(url) # Request: fetch data data = response.text # Convert data to string obj = json.loads(data) # Convert data to json data type: python dict type # print("Out: ", obj) # Control message ### Extract API Values ### date = obj["date"] # Extract date gbp_rate = obj["rates"]["GBP"] # Read Value for gbp rate usd_rate = obj["rates"]["USD"] # Read Value for usd rate # print("On " + date + " 1 EUR equals " + str(gbp_rate)+ " GBP, and " + str(usd_rate)+ " USD.") # Display fetched values return (date,gbp_rate, usd_rate)
def CheckVersion(): ''' CheckVersion Return values: Current Release Number GitHub Release number ''' GithubVersion = None try: response = requests.get(autosub.VERSIONURL) Temp = response.text.split("'") if 'Alpha' in Temp[1]: GithubVersion = Temp[1].split(' ')[1] else: GithubVersion = Temp[1] except Exception as error: log.error('CheckVersion: Problem getting the version form github. Error is: %s' % error) GithubVersion ='0.0.0' return GithubVersion
def _update_library(plexserverhost, plexserverport, plexserverusername, plexserverpassword, plexservertoken): if not plexserverhost: plexserverhost = autosub.PLEXSERVERHOST if not plexserverport: plexserverport = int(autosub.PLEXSERVERPORT) if not plexserverusername: plexserverusername = autosub.PLEXSERVERUSERNAME if not plexserverpassword: plexserverpassword = autosub.PLEXSERVERPASSWORD if not plexservertoken: plexservertoken = autosub.PLEXSERVERTOKEN #Maintain support for older Plex installations without myPlex if not plexservertoken and not plexserverusername and not plexserverpassword: url = "http://%s:%s/library/sections" % (plexserverhost, plexserverport) try: response = requests.get(url, timeout=10) except: log.error("Error while trying to contact plexmedia server") return False #SubLines = re.findall('<tr class="epeven completed">(.*?)</tr>', SubOverviewPage, re.S) else: #Fetch X-Plex-Token if it doesn't exist but a username/password do if not plexservertoken and plexserverusername and plexserverpassword: log.info("Fetching a new X-Plex-Token from plex.tv") authheader = "Basic %s" % base64.encodestring( '%s:%s' % (plexserverusername, plexserverpassword))[:-1] headers = { "Authorization": authheader, "X-Plex-Product": "AutoSub Notifier", "X-Plex-Client-Identifier": "b3a6b24dcab2224bdb101fc6aa08ea5e2f3147d6", "X-Plex-Version": "1.0" } try: response = requests.post("https://plex.tv/users/sign_in.xml", headers=headers, verify=autosub.CERT, timeout=10) except: log.error("Error while trying to contact plexmediaserver") return False auth_tree = ET.fromstring(response.text) plexservertoken = auth_tree.findall( ".//authentication-token")[0].text autosub.PLEXSERVERTOKEN = plexservertoken if plexservertoken: #Add X-Plex-Token header for myPlex support workaround try: response = requests.get('%s/%s?X-Plex-Token=%s' % ("%s:%s" % (plexserverhost, plexserverport), 'library/sections', plexservertoken), timeout=10) except Exception as error: log.error("Error from get header. Error is: %s" % error) return False xml_sections = ET.fromstring(response.text) try: sections = xml_sections.findall('Directory') except: pass if not sections: log.info("Server not running on: %s:%s" % (plexserverhost, plexserverport)) return False for s in sections: if s.get('type') == "title": if plexservertoken: try: requests.get('%s/%s?X-Plex-Token=%s' % ("%s:%s" % (plexserverhost, plexserverport), "library/sections/%s/refresh" % (s.get('key')), plexservertoken), timeout=10) log.info("TV Shows library (%s) is currently updating." % s.get('title')) return True except Exception, e: log.error("Error updating library section: %s" % e) return False else: url = "http://%s:%s/library/sections/%s/refresh" % ( plexserverhost, plexserverport, s.getAttribute('key')) try: requests.get(url, timeout=10) log.info("TV Shows library is currently updating.") return True except Exception, e: log.error("Error updating library section: %s" % e) return False
"b3a6b24dcab2224bdb101fc6aa08ea5e2f3147d6", "X-Plex-Version": "1.0" } response = requests.post("https://plex.tv/users/sign_in.xml", headers=headers) auth_tree = ET.fromstring(response.text) plexservertoken = auth_tree.findall( ".//authentication-token")[0].text autosub.PLEXSERVERTOKEN = plexservertoken if plexservertoken: #Add X-Plex-Token header for myPlex support workaround response = requests.get('%s/%s?X-Plex-Token=%s' % ("%s:%s" % (plexserverhost, plexserverport), 'library/sections', plexservertoken)) xml_sections = ET.fromstring(response.text) sections = xml_sections.findall('Directory') if not sections: log.info("plexmediaserver: Server not running on: %s:%s" % (plexserverhost, plexserverport)) return False for s in sections: if s.get('type') == "show": try: requests.get(
def _update_library(plexserverhost, plexserverport, plexserverusername, plexserverpassword, plexservertoken): if not plexserverhost: plexserverhost = autosub.PLEXSERVERHOST if not plexserverport: plexserverport = int(autosub.PLEXSERVERPORT) if not plexserverusername: plexserverusername = autosub.PLEXSERVERUSERNAME if not plexserverpassword: plexserverpassword = autosub.PLEXSERVERPASSWORD if not plexservertoken: plexservertoken = autosub.PLEXSERVERTOKEN #Maintain support for older Plex installations without myPlex if not plexservertoken and not plexserverusername and not plexserverpassword: url = "http://%s:%s/library/sections" % (plexserverhost, plexserverport) try: response = requests.get(url) except: log.error("plexmediaserver: Error while trying to contact plexmedia server") return False #SubLines = re.findall('<tr class="epeven completed">(.*?)</tr>', SubOverviewPage, re.S) else: #Fetch X-Plex-Token if it doesn't exist but a username/password do if not plexservertoken and plexserverusername and plexserverpassword: log.info("plexmediaserver: Fetching a new X-Plex-Token from plex.tv") authheader = "Basic %s" % base64.encodestring('%s:%s' % (plexserverusername, plexserverpassword))[:-1] headers = { "Authorization": authheader, "X-Plex-Product": "AutoSub Notifier", "X-Plex-Client-Identifier": "b3a6b24dcab2224bdb101fc6aa08ea5e2f3147d6", "X-Plex-Version": "1.0" } try: response = requests.post("https://plex.tv/users/sign_in.xml", headers=headers); except: log.error("Plex Media Server: Error while trying to contact plexmediaserver") return False auth_tree = ET.fromstring(response.text) plexservertoken = auth_tree.findall(".//authentication-token")[0].text autosub.PLEXSERVERTOKEN = plexservertoken if plexservertoken: #Add X-Plex-Token header for myPlex support workaround response = requests.get('%s/%s?X-Plex-Token=%s' % ( "%s:%s" % (plexserverhost, plexserverport), 'library/sections', plexservertoken )) xml_sections = ET.fromstring(response.text) try: sections = xml_sections.findall('Directory') except: pass if not sections: log.info("plexmediaserver: Server not running on: %s:%s" % (plexserverhost, plexserverport)) return False for s in sections: if s.get('type') == "show": if plexservertoken: try: requests.get('%s/%s?X-Plex-Token=%s' % ( "%s:%s" % (plexserverhost, plexserverport), "library/sections/%s/refresh" % (s.get('key')), plexservertoken )) log.info("plexmediaserver: TV Shows library (%s) is currently updating." % s.get('title')) return True except Exception, e: log.error("plexmediaserver: Error updating library section: %s" % e) return False else: url = "http://%s:%s/library/sections/%s/refresh" % (plexserverhost, plexserverport, s.getAttribute('key')) try: requests.get(url) log.info("Plex Media Server: TV Shows library is currently updating.") return True except Exception, e: log.error("Plex Media Server: Error updating library section: %s" % e) return False
"X-Plex-Product": "AutoSub Notifier", "X-Plex-Client-Identifier": "b3a6b24dcab2224bdb101fc6aa08ea5e2f3147d6", "X-Plex-Version": "1.0" } response = requests.post("https://plex.tv/users/sign_in.xml", headers=headers); auth_tree = ET.fromstring(response.text) plexservertoken = auth_tree.findall(".//authentication-token")[0].text autosub.PLEXSERVERTOKEN = plexservertoken if plexservertoken: #Add X-Plex-Token header for myPlex support workaround response = requests.get('%s/%s?X-Plex-Token=%s' % ( "%s:%s" % (plexserverhost, plexserverport), 'library/sections', plexservertoken )) xml_sections = ET.fromstring(response.text) sections = xml_sections.findall('Directory') if not sections: log.info("plexmediaserver: Server not running on: %s:%s" % (plexserverhost, plexserverport)) return False for s in sections: if s.get('type') == "show": try: requests.get('%s/%s?X-Plex-Token=%s' % (