Ejemplo n.º 1
0
def bing_search(query, search_type):
    #search_type: Web, Image, News, Video
    key = 'F6emP6kR5rnPBZce9mUpOHPJbgLYobRKlkb2Z5p/Bg0'
    query = urllib.quote(query)
    # create credential for authentication
    user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; FDM; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 1.1.4322)'
    credentials = (':%s' % key).encode('base64')[:-1]
    auth = 'Basic %s' % credentials
    url = 'https://api.datamarket.azure.com/Data.ashx/Bing/Search/' + search_type + '?Query=%27' + query + '%27&$top=5&$format=json'
    request = urllib2.Request(url)
    request.add_header('Authorization', auth)
    request.add_header('User-Agent', user_agent)
    request_opener = urllib2.build_opener()
    response = request_opener.open(request)
    response_data = response.read()
    json_result = json.loads(response_data)
    result_list = json_result['d']['results']

    string01 = str(ascii1.main(result_list[0]['Title']))
    string02 = str(ascii1.main(result_list[0]['Description']))
    pos1 = string02.find('(')
    pos2 = string02.find(')')
    string02 = string02[:pos1] + string02[pos2 + 1:]

    talks.main(string01)
    talks.main(string02)

    print result_list[0]['Title']
    print result_list[0]['Description']

    return result_list
Ejemplo n.º 2
0
def bing_search(query, search_type):
    #search_type: Web, Image, News, Video
    key= 'F6emP6kR5rnPBZce9mUpOHPJbgLYobRKlkb2Z5p/Bg0'
    query = urllib.quote(query)
    # create credential for authentication
    user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; FDM; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 1.1.4322)'
    credentials = (':%s' % key).encode('base64')[:-1]
    auth = 'Basic %s' % credentials
    url = 'https://api.datamarket.azure.com/Data.ashx/Bing/Search/'+search_type+'?Query=%27'+query+'%27&$top=5&$format=json'
    request = urllib2.Request(url)
    request.add_header('Authorization', auth)
    request.add_header('User-Agent', user_agent)
    request_opener = urllib2.build_opener()
    response = request_opener.open(request)
    response_data = response.read()
    json_result = json.loads(response_data)
    result_list = json_result['d']['results']
    
    string01=str(ascii1.main(result_list[0]['Title']))
    string02=str(ascii1.main(result_list[0]['Description']))
    pos1=string02.find('(')
    pos2=string02.find(')')
    string02=string02[:pos1]+string02[pos2+1:]


    talks.main(string01)
    talks.main(string02)
    
    print result_list[0]['Title']
    print result_list[0]['Description']

    return result_list
Ejemplo n.º 3
0
def do(speech):

     factory = ChatterBotFactory()

     bot1 = factory.create(ChatterBotType.CLEVERBOT)
     bot1session = bot1.create_session()

     bot2 = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477')
     bot2session = bot2.create_session()

     while(speech!="bye bye"):

        if speech.find("search twitter for")!=-1:
             speech=speech.replace("search twitter for",'')
             search.main(speech)
        elif speech.find("show twitter trend")!=-1:
             trending.main()
        elif speech.find("tell the weather")!=-1:
             weather.main()
        elif speech.find('show my e-mail')!=-1:
             mailtest.main()
        elif speech.find('send email')!=-1:
             mailtest2.main()
        elif speech.find('search bing for')!=-1:
             speech=speech.replace('search bing for','')
             bingsearch.main(speech)
        else:
             s = bot2session.think(speech);
             print 'yam> ' + s
             talks.main(s) 
            

        speech=listen()
        speech=speech.lower()     
Ejemplo n.º 4
0
def search_api(q):
    tweets = api.search(q, 'en')
    count = 0
    for tweet in tweets:

        try:
            tosay = str(ascii1.main(tweet.text))
            pos = tosay.find("http")
            tosay = tosay[:pos]
            pos = tosay.find(":")
            tosay = tosay[pos + 1:]
            print tweet.text
            print '\n'
            talks.main(tosay)
            count += 1
            if count == 5:
                break
        except:
            continue
Ejemplo n.º 5
0
def search_api(q):
     tweets = api.search(q,'en')
     count=0
     for tweet in tweets:
       

       try:
        tosay=str(ascii1.main(tweet.text))
        pos=tosay.find("http")
        tosay=tosay[:pos]
        pos=tosay.find(":")
        tosay=tosay[pos+1:]
        print tweet.text
        print '\n'
        talks.main(tosay)
        count+=1
        if count==5:
         break
       except:
        continue
Ejemplo n.º 6
0
def main():

    owm = pyowm.OWM(
        '528f493a92ec155d0833ec740c511075')  # You MUST provide a valid API key

    # You have a pro subscription? Use:
    # owm = pyowm.OWM(API_key='your-API-key', subscription_type='pro')

    # Will it be sunny tomorrow at this time in Milan (Italy) ?
    forecast = owm.daily_forecast("Kanpur,in")
    tomorrow = pyowm.timeutils.tomorrow()

    # Always True in Italy, right? ;-)

    # Search for current weather in London (UK)
    observation = owm.weather_at_place('Kanpur,in')
    w = observation.get_weather()
    #print(w)                      # <Weather - reference time=2013-12-18 09:20,
    # status=Clouds>

    # Weather details
    print "The wind speed is " + str((w.get_wind())['speed'])
    talks.main("The wind speed is " + str(
        (w.get_wind())['speed']))  # {'speed': 4.6, 'deg': 330}
    print "The relative humidity is " + str(w.get_humidity())
    talks.main("The relative humidity is " + str(w.get_humidity()))  # 87
    temp = w.get_temperature('celsius')
    print "The current temperature is " + str(temp['temp'])
    talks.main("The current temperature is " + str(temp['temp']))

    if forecast.will_be_sunny_at(tomorrow) == True:
        print "Thankfully, It may be sunny tomorrow"
        talks.main("Thankfully, It may be sunny tomorrow")
    else:
        print "Buckle up! It may not be sunny tomorrow"
        talks.main("Buckle up! It may not be sunny tomorrow")

    # Search current weather observations in the surroundings of
    # lat=22.57W, lon=43.12S (Rio de Janeiro, BR)
    observation_list = owm.weather_around_coords(-22.57, -43.12)
Ejemplo n.º 7
0
def ListThreadsWithLabels(service, user_id, label_ids=[]):
  """List all Threads of the user's mailbox with label_ids applied.

  Args:
    service: Authorized Gmail API service instance.
    user_id: User's email address. The special value "me"
    can be used to indicate the authenticated user.
    label_ids: Only return Threads with these labelIds applied.

  Returns:
    List of threads that match the criteria of the query. Note that the returned
    list contains Thread IDs, you must use get with the appropriate
    ID to get the details for a Thread.
  """
  try:
    response = service.users().threads().list(userId=user_id,
                                              labelIds=label_ids).execute()
    threads = []
    if 'threads' in response:
      threads.extend(response['threads'])

    while 'nextPageToken' in response:
      page_token = response['nextPageToken']
      response = service.users().threads().list(userId=user_id,
                                                labelIds=label_ids,
                                                pageToken=page_token).execute()
      threads.extend(response['threads'])

    j=0
    for i in threads:
        if(j<5):
            print (i['snippet'])
            talks.main(str(i['snippet']))
            j=j+1
        else:
            break

  except errors.HttpError, error:
      print ('An error occurred: %s' % error)
Ejemplo n.º 8
0
def main():
    #consumer key, consumer secret, access token, access secret.
    ckey="v2jwaSVt27THEOzANj8xi8lvO"
    csecret="1Cxd4B6lylQuY3TsOJCpSzrWImjfeZXDrD0hGHgo3vgZPFZVLt"
    atoken="3973064473-HXjQzLJAevVFxcULXJQncG8LsLXs0BbGTqnhADC"
    asecret="vZrpw5UKtqiH3TCEmN6jXhOj4HZbHaKoRrv2mnRMcYT9M"

    auth=tweepy.OAuthHandler(ckey,csecret)
    auth.set_access_token(atoken,asecret)

    api=tweepy.API(auth)

    bla=api.trends_place(2295411)
    json.dumps(bla)
    count=0
    for blas in bla:
       for pa in blas[u'trends']:
         talks.main(pa[u'name'])
         print pa[u'name']
         count+=1
         if count==5:
            break