def getCompletionArray(word): response = urlopen('https://ac.duckduckgo.com/ac/?q=' + word.replace(' ', '%20')) data = response.read().replace('autocompleteCallback(', '').replace(');', '') array = [d['phrase'] for d in parseJson(data)] return array
def getFeed(self): params = urllib.parse.urlencode({ 'access_token': access_token, 'fields': ','.join(['id', 'created_time', 'message', 'from', 'object_id']) }) req = '/v2.4/%d/feed?%s' % (group_id, params) conn = http.client.HTTPSConnection('graph.facebook.com') conn.request('GET', req) res = conn.getresponse() json = parseJson(res.read().decode("utf-8")) conn.close() feed = [] for i in json['data']: if 'message' not in i: continue feed.append({ 'post_id': i['id'], 'time': (parseTime(i['created_time'])), 'message': i['message'], 'from': i['from'], 'image': i['object_id'] if 'object_id' in i else '' }) return feed
def authorize(self, user_id, user_access_token): params = urllib.parse.urlencode({'access_token': user_access_token}) req = '/me?%s' % (params) conn = http.client.HTTPSConnection('graph.facebook.com') conn.request('GET', req) res = conn.getresponse() statusCode = res.status json = parseJson(res.read().decode('utf-8')) conn.close() if statusCode == 200 and str(json['id']) == str(user_id): return str(json['id']) return ''
async def receive_and_handle_messages(self, timeout=None): """ Handles all pending messages from the homee websocket connection. :param is_response_expected: True if an API response is expected :since: 1.0.0 """ try: timeout_remaining = (0 if (timeout is None) else timeout) while True: if (timeout == 0): message = await self._socket.receive() else: time_started = time() receive_timeout = (timeout_remaining if (timeout_remaining > 0) else self.__class__.API_MESSAGE_TIMEOUT) message = await self._socket.receive( timeout=receive_timeout) if (timeout_remaining > 0): timeout_remaining -= time() - time_started # if message.type == WSMsgType.CLOSED: break elif message.type == WSMsgType.ERROR: raise RuntimeError(message.data) elif message.type == WSMsgType.TEXT: await self._handle_message(parseJson(message.data)) # except FutureTimeoutError: pass
def getCompletionArray(word): response = urlopen('https://ac.duckduckgo.com/ac/?q='+word.replace(' ', '%20')) data = response.read().replace('autocompleteCallback(', '').replace(');', '') array = [d['phrase'] for d in parseJson(data)] return array
import matplotlib.pyplot as plt from json import loads as parseJson from re import search as RegEx # Lê o arquivo "database.json" em forma de lista. database = parseJson(open('./database.json', 'r').read()) # ... if len(database[0]) == 0: print('\n Não há dados no banco de dados!\n') # <--- exit() # Organiza a lista de datas. Datas = [] for z in range(len(database)): if database[z][0].split(' ')[0] not in Datas: Datas.append(database[z][0].split(' ')[0]) print('\n Datas disponíveis para pesquisa:\n {0}\n'.format( str(Datas).strip('[]'))) # Primeiro print. # O IF e ELIF são responsáveis por verificar # se o valor foi digitado corretamente. print(' Selecione uma data (ou apenas aperte [enter] para continuar):') matchData = input(' :: DD/MM :: ').strip() if not (RegEx("\d\d\/\d\d", str(matchData)) or matchData == ''): print('\n Digite uma data no formato DD/MM!\n') exit() elif not (matchData in Datas or matchData == ''): print('\n Esta data não está na lista!\n') exit()