def auth_route_logout(): if 'redirect' in request.values or "realm" in request.values: url = build_url(request.values.get("realm", ""), request.values.get("redirect", "")) else: url = build_url("", "") if g.user: del session['id'] return flashy(u"You have been logged out!", "success", u=url) return flashy(u"You are not currently logged in!", u=url)
def _preGenerateTrack(self, artist): if 0 < len(self.tracks[artist]): return True log("Loading tracks for artist: " + str(artist.encode('utf-8'))) url = build_url( lastfmApi, { 'method': 'artist.gettoptracks', 'artist': artist.encode('utf-8'), 'format': 'json', 'api_key': lastfmApiKey }) # xbmc.log(url) reply = urllib.urlopen(url) # xbmc.log(str(reply)) resp = json.load(reply) if "error" in resp: raise Exception("Error! DATA: " + str(resp)) else: # xbmc.log(str(resp)) log('Successfully loaded artist tracks') for t in resp['toptracks']['track']: trackname = t['name'].lower() artistname = t['artist']['name'].lower() xbmc.log( str(artistname.encode('utf-8')) + " -- " + str(trackname.encode('utf-8'))) # Put artists and tracks into the associative array self.tracks[artist].append(trackname) return True
def add_camera(request: Request, camera: CameraModel): try: model = ConfigCameraModel.parse_obj({ "name": camera.name, "type": CameraType.onvif, "manage_url": build_url({ "scheme": "http", "host": camera.host, "username": camera.username, "password": camera.password }) }) camera = request.app.camera_manager.add(model) config.cameras[camera.id] = model config.save() return {"success": True, "results": [camera.get_features()]} except Exception as e: raise APIException(status_code=HTTP_400_BAD_REQUEST, detail=str(e))
def listItems(tvshowid): url = build_url(addonUrl, {'action': 'play', 'tvshowid': tvshowid, 'minutes': 30}) li = xbmcgui.ListItem('30 minutes', iconImage='DefaultFolder.png') xbmcplugin.addDirectoryItem(handle=addonHandle, url=url, listitem=li, isFolder=False) url = build_url(addonUrl, {'action': 'play', 'tvshowid': tvshowid, 'minutes': 60}) li = xbmcgui.ListItem('60 minutes', iconImage='DefaultFolder.png') xbmcplugin.addDirectoryItem(handle=addonHandle, url=url, listitem=li, isFolder=False) url = build_url(addonUrl, {'action': 'play', 'tvshowid': tvshowid, 'minutes': 90}) li = xbmcgui.ListItem('90 minutes', iconImage='DefaultFolder.png') xbmcplugin.addDirectoryItem(handle=addonHandle, url=url, listitem=li, isFolder=False) url = build_url(addonUrl, {'action': 'play', 'tvshowid': tvshowid, 'minutes': 0}) li = xbmcgui.ListItem('Custom length...', iconImage='DefaultFolder.png') xbmcplugin.addDirectoryItem(handle=addonHandle, url=url, listitem=li, isFolder=False) xbmcplugin.addSortMethod(addonHandle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.endOfDirectory(addonHandle)
def parse(src): kml_file = urllib.urlopen(build_url(os.path.join(os.environ['KML_DATA'], src), 'file')) doc = parser.parse(kml_file).getroot() JSONpolygon = [] try: for el in doc.Document.Folder.Placemark: polygon = el.Polygon.outerBoundaryIs.LinearRing data = el.ExtendedData.SchemaData[0].SimpleData props = {} for prop in data: props.update({prop.attrib['name']: prop.text}) # Clean coordinates data c_coords = [float(c.replace('0-','-')) for c in polygon.coordinates.text.strip().replace('\n',',').replace(' ','').split(',') if c != '0'] coords = [str(lat)+' '+str(lon) for lat,lon in zip(c_coords[0::2],c_coords[1::2])] JSONpolygon.append({ 'type': 'Feature', 'geometry': { 'type': 'Polygon', 'coordinates': coords }, 'properties': props }) except Exception: print(traceback.format_exc()) return JSONpolygon
def _preGenerateTrack(self, artist): if 0 < len(self.tracks[artist]): return True log("Loading tracks for artist: " + str(artist.encode('utf-8'))) url = build_url(lastfmApi, {'method': 'artist.gettoptracks', 'artist': artist.encode('utf-8'), 'format': 'json', 'api_key': lastfmApiKey}) # xbmc.log(url) reply = urllib.urlopen(url) # xbmc.log(str(reply)) resp = json.load(reply) if "error" in resp: raise Exception("Error! DATA: " + str(resp)) else: # xbmc.log(str(resp)) log('Successfully loaded artist tracks') for t in resp['toptracks']['track']: trackname = t['name'].lower() artistname = t['artist']['name'].lower() xbmc.log(str(artistname.encode('utf-8')) + " -- " + str(trackname.encode('utf-8'))) # Put artists and tracks into the associative array self.tracks[artist].append(trackname) return True
def loadRecentTracks(self, username): url = build_url( lastfmApi, { 'method': 'user.getrecenttracks', 'user': username, 'format': 'json', 'api_key': lastfmApiKey, 'limit': 500, 'page': 1 }) # xbmc.log(url) reply = urllib.urlopen(url) # xbmc.log(str(reply)) resp = json.load(reply) if "error" in resp: raise Exception("Error! DATA: " + str(resp)) else: # xbmc.log(str(resp)) log('Successfully loaded recent tracks') if self.dlgProgress.iscanceled(): return None self.dlgProgress.update(90) for t in resp['recenttracks']['track']: trackname = t['name'].lower() artistname = t['artist']['#text'].lower() #log(str(artistname.encode('utf-8')) + " -- " + str(trackname.encode('utf-8'))) self.history.addEntry(artistname, trackname)
def request_synopsis(self, programme): programme_id = TIMES_DESC_QUERY_PROGRAMME_ID + programme.get( 'programmeid') channel_id = TIMES_DESC_QUERY_CHANNEL_ID + programme.get('channelid') start_time = TIMES_DESC_QUERY_START_TIME + programme.get('start') path = 'tv/programmes/params/tvprogramme/' + programme_id + '/' + channel_id + '/' + start_time payload = {QUERY_PID: programme.get('_id')} url = build_url('http', TIMES_LISTING_API, path) self.put_request(url, payload=payload)
def before_request(): g.user = None if request.path.startswith("/static"): return if 'id' in session: try: g.user = User.get(User.id == session['id']) except User.DoesNotExist: return flashy(u"Your session is invalid!", "error", u=build_url("", ""))
def __post__(self, env, username, email): id, code = self.app.request_new_password(username, email) url = util.build_url("/html/user/%s/password/reset/%s", config.WEBSITE_URL, username, id) v = view.JSONView(201) v.headers["Location"] = url v.headers["ETag"] = util.hash(url) m = {"Location": url} v.bind(m) return v
def __post__(self, env, username, email): id, code = self.app.request_account(username, email) url = util.build_url("/html/registration/%s", config.WEBSITE_URL, id) v = view.JSONView(201) v.headers["Location"] = url v.headers["ETag"] = util.hash(url) m = {"Location": url} v.bind(m) return v
def prepare(self): # populate queue with data for category in TV_LISTINGS_CATEGORY: for lang in TV_LISTING_LANGUAGES: payload = { QUERY_PARAM_GENRE_NAME: category, QUERY_PARAM_USER_ID: '0', # default is 0 QUERY_PARAM_LANGUAGE_NAME: lang } url = build_url('http', TIMES_LISTING_API, TIMES_CHANNEL_LIST_ENDPOINT, None) self.put_request(url, payload=payload)
def loadTracks(self, username, page): url = build_url(lastfmApi, {'method': 'user.getlovedtracks', 'user': username, 'format': 'json', 'api_key': lastfmApiKey, 'limit': 500, 'page': page}) # xbmc.log(url) reply = urllib.urlopen(url) # xbmc.log(str(reply)) resp = json.load(reply) if "error" in resp: raise Exception("Error! DATA: " + str(resp)) else: # xbmc.log(str(resp)) log('Successfully loaded loved tracks, page:' + str(page)) return resp['lovedtracks']
def loadTracks(self, username, page): url = build_url(lastfmApi, {'method': 'user.gettopartists', 'user': username, 'format': 'json', 'api_key': lastfmApiKey, 'limit': 500, 'page': page}) # xbmc.log(url) reply = urllib.urlopen(url) # xbmc.log(str(reply)) resp = json.load(reply) if "error" in resp: raise Exception("Error! DATA: " + str(resp)) else: # xbmc.log(str(resp)) log('Successfully loaded artists, page:' + str(page)) total = int(resp['topartists']['@attr']['total']) self.avgPlaycount = self.playcount / total + 1 return resp['topartists']
def fetch_request(self, channels_param, from_date, to_date): """ Create a request for querying TIMES API :param channels_param: List of channels to query, comma separated :param from_date: From date :param to_date: To date :return: None """ payload = { QUERY_PARAM_CHANNEL_LIST: channels_param, QUERY_PARAM_USER_ID: 0, QUERY_PARAM_FROM_DATE_TIME: from_date, QUERY_PARAM_TO_DATE_TIME: to_date } url = build_url('http', TIMES_LISTING_API, TIMES_LISTINGS_ENDPOINT, None) self.put_request(url, payload=payload)
def loadTracks(self, username, page): url = build_url( lastfmApi, { 'method': 'user.getlovedtracks', 'user': username, 'format': 'json', 'api_key': lastfmApiKey, 'limit': 500, 'page': page }) # xbmc.log(url) reply = urllib.urlopen(url) # xbmc.log(str(reply)) resp = json.load(reply) if "error" in resp: raise Exception("Error! DATA: " + str(resp)) else: # xbmc.log(str(resp)) log('Successfully loaded loved tracks, page:' + str(page)) return resp['lovedtracks']
def request_account(self, username, email): # validate parameters: if not validate_username(username): raise exception.InvalidParameterException("username") if not validate_email(email): raise exception.InvalidParameterException("email") # store request in database: with self.__create_db_connection__() as conn: with conn.enter_scope() as scope: # test if user account or email already exist: if self.__user_db.username_or_email_assigned(scope, username, email): raise exception.ConflictException("Username or email already assigned.") # generate request id & code: id = util.generate_junk(config.REQUEST_ID_LENGTH, secure=True) while self.__user_db.user_request_id_exists(scope, id): id = util.generate_junk(config.REQUEST_ID_LENGTH, secure=True) code = util.generate_junk(config.REQUEST_CODE_LENGTH, secure=True) # save user request: self.__user_db.create_user_request(scope, id, code, username, email) # generate mail: url = util.build_url("/html/registration/%s?code=%s", config.WEBSITE_URL, id, code) tpl = template.AccountRequestMail(config.DEFAULT_LANGUAGE) tpl.bind(username=username, url=url) subject, body = tpl.render() self.__mail_db.push_mail(scope, subject, body, email) mailer.ping(config.MAILER_HOST, config.MAILER_PORT) scope.complete() return id, code
def loadRecentTracks(self, username): url = build_url(lastfmApi, {'method': 'user.getrecenttracks', 'user': username, 'format': 'json', 'api_key': lastfmApiKey, 'limit': 500, 'page': 1}) # xbmc.log(url) reply = urllib.urlopen(url) # xbmc.log(str(reply)) resp = json.load(reply) if "error" in resp: raise Exception("Error! DATA: " + str(resp)) else: # xbmc.log(str(resp)) log('Successfully loaded recent tracks') if self.dlgProgress.iscanceled(): return None self.dlgProgress.update(90) for t in resp['recenttracks']['track']: trackname = t['name'].lower() artistname = t['artist']['#text'].lower() #log(str(artistname.encode('utf-8')) + " -- " + str(trackname.encode('utf-8'))) self.history.addEntry(artistname, trackname)
def request_new_password(self, username, email): with self.__create_db_connection__() as conn: with conn.enter_scope() as scope: self.__test_active_user__(scope, username) user = self.__user_db.get_user(scope, username) # test if email address is correct: if email.lower() <> user["email"].lower(): raise exception.WrongEmailAddressException() # delete existing request ids: self.__user_db.remove_password_requests_by_user_id(scope, user["id"]) # create request id & code: id = util.generate_junk(config.REQUEST_ID_LENGTH, secure=True) while self.__user_db.password_request_id_exists(scope, id): id = util.generate_junk(config.REQUEST_ID_LENGTH, secure=True) code = util.generate_junk(config.REQUEST_CODE_LENGTH, secure=True) url = util.build_url("/html/user/%s/password/reset/%s?code=%s", config.WEBSITE_URL, username, id, code) # save password request: self.__user_db.create_password_request(scope, id, code, user["id"]) # generate mail: tpl = template.PasswordRequestedMail(self.__get_language__(user)) tpl.bind(username=username, url=url) subject, body = tpl.render() self.__mail_db.push_user_mail(scope, subject, body, user["id"]) mailer.ping(config.MAILER_HOST, config.MAILER_PORT) scope.complete() return id, code
def listTvshows(): tvshows = getTvshows() listing = [] for e in tvshows: #log(str(e)) li = xbmcgui.ListItem(e['title'], iconImage='DefaultFolder.png') url = build_url(addonUrl, {'action': 'choosetime', 'tvshowid': e['tvshowid']}) li.setInfo('video', {'title': e['title']}) art = {} if 'thumbnail' in e: art['thumb'] = e['thumbnail'] if 'art' in e: if 'banner' in e['art']: art['banner'] = e['art']['banner'] if 'fanart' in e['art']: art['fanart'] = e['art']['fanart'] li.setArt(art) isFolder = True listing.append((url, li, isFolder)) xbmcplugin.addDirectoryItems(addonHandle, listing, len(listing)) xbmcplugin.addSortMethod(addonHandle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.endOfDirectory(addonHandle)
def request_imdb(self, title, pid, id=None): """ Create a request for querying OMDB API :param title: Title of the movie/tv show :param pid: Programme id of the listings :param id: IMDb ID if available :return: None """ if not title and not id: return url = build_url('http', IMDB_API) payload = { IMDB_QUERY_PLOT_TYPE: 'short', IMDB_QUERY_RETURN_TYPE: 'json', QUERY_PID: pid } if id: payload[IMDB_QUERY_BY_ID] = id else: payload[IMDB_QUERY_BY_TITLE] = title self.put_request(url, payload=payload)
def loadTracks(self, username, page): url = build_url( lastfmApi, { 'method': 'user.gettopartists', 'user': username, 'format': 'json', 'api_key': lastfmApiKey, 'limit': 500, 'page': page }) # xbmc.log(url) reply = urllib.urlopen(url) # xbmc.log(str(reply)) resp = json.load(reply) if "error" in resp: raise Exception("Error! DATA: " + str(resp)) else: # xbmc.log(str(resp)) log('Successfully loaded artists, page:' + str(page)) total = int(resp['topartists']['@attr']['total']) self.avgPlaycount = self.playcount / total + 1 return resp['topartists']
try: lastfmAddon = xbmcaddon.Addon('service.scrobbler.lastfm') lastfmUser = lastfmAddon.getSetting('lastfmuser') except RuntimeError: pass #xbmc.log(str(args)) action = args.get('action', None) folder = args.get('folder', None) #xbmc.log('openlast: folder=' + str(folder)) #, xbmc.LOGDEBUG) #xbmc.log('openlast: action=' + str(action)) #, xbmc.LOGDEBUG) if folder is None: url = build_url(addonUrl, {'folder': 'similarArtist'}) li = xbmcgui.ListItem('Similar artist radio', iconImage='DefaultFolder.png') xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True) if '' != lastfmUser: url = build_url(addonUrl, {'folder': 'lastfm', 'username': lastfmUser}) # xbmc.log(url) li = xbmcgui.ListItem('Personal radio for Last.fm user: '******'DefaultFolder.png') xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True) url = build_url(addonUrl, {'folder': 'lastfm'}) li = xbmcgui.ListItem('Personal radio for Last.fm user...', iconImage='DefaultFolder.png') xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True) xbmcplugin.endOfDirectory(addon_handle)
def auth_route_login(): if g.user is not None: return flashy(u"You are already logged in!", u=build_url("", "")) return openid.try_login('http://steamcommunity.com/openid')
def auth_render_index(): if not g.user: return redirect(build_url("auth", "login")) return render_template("settings.html")
def maz_route_inventory(): if not g.user: return redirect(build_url("auth", "login") + "?next=" + build_url("maz", "inventory")) return render_template("maz/inventory.html")
def get_avatar(self): """ Returns a URL to the users avatar. (Comes from the auth server) """ return build_url("auth", "avatar/%s" % self.steamid)
def vac_route_tracked(): if not g.user: redirect(build_url("auth", "login"))