Example #1
0
def news_search():
	entry = History.query.descending('mongo_id').first()
	types = ['locality', 'administrative_area_level_1']
	c_loc_geo = get_geonames(entry.current_location.geocode[0], entry.current_location.geocode[1], types)
	c_loc_name=[]
	for geoname in c_loc_geo:
		c_loc_name.append(geoname['long_name'])
	c_loc = ','.join(c_loc_name)
	
	print c_loc
	query = urllib.urlencode({'q': c_loc})
	url = ('https://ajax.googleapis.com/ajax/services/search/news?v=1.0&%s' % query)
	print url
	request = urllib2.Request(url)
	response = urllib2.urlopen(request)
	results = simplejson.load(response)
	hits = results['responseData']['results']
	for h in hits[:app.config['NUMBER_OF_NEWS']]:
		title = h['titleNoFormatting']
		print title
		print shorten(h['unescapedUrl'])
		if len(title) > 100:
			title = title[:100] + "..."
		news_tweet = title + " " + shorten(h['unescapedUrl'])
		print news_tweet
Example #2
0
def getitem(url, rickroll):
    feed = feedparser.parse(url)
    if len(feed) == 0:
        return "Empty or broken feed. Sorry :S"

    choice = random.randint(0, len(feed)-1)
    toreturn = "%s " % feed['entries'][choice]['title']
    if rickroll:
        #rickroll
        toreturn = toreturn + urlshortener.shorten("http://www.youtube.com/watch?v=oHg5SJYRHA0")
    else:
        toreturn = toreturn + urlshortener.shorten(feed['entries'][choice]['link'])
    return removeNonAscii(toreturn)
Example #3
0
  def post(self):
    user = users.get_current_user()
    only_validate = self.request.get("validate")
    if user:
      #get params
      url = self.request.get("url")
      linkmap = self.request.get("linkmap")
      linkmap_key = self.request.get("linkmap_key")
      link = models.GeoLink(user=user)
      if url:
        link.url = url
      else:
        link.linkmap = linkmap
        link.linkmap_key = linkmap_key
      valid_input = False
      try:
        valid_input = link.validate()
      except Exception, e:
        self.response.out.write(e)

      if only_validate == "" and valid_input == True:
        key = link.put()

        #create shortlink goo.gl
        credentials = StorageByKeyName(models.Credentials, user.user_id(), 'credentials').get()
        if credentials and credentials.invalid == False:
          link.shortlink = urlshortener.shorten(models.GEOLINK_BASE_URL + 'l/' + str(key), credentials)
          link.put()
        #self.response.out.write("saved the link " + url)
        self.redirect("/dashboard/")
      elif only_validate and valid_input == True:
        self.response.out.write("valid")
Example #4
0
def handlewho(connection, event):
    print("whois handler")
    global reply
    try:
        ip = event.arguments()[2]
        m = re.match('\\w+/', ip)
        if m is not None:
            msg = "Error: User has a hostmask"
        else:
            m = re.match('^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$', ip) 
            if m is None:
                ip = socket.gethostbyname(ip)
            root = etree.parse('http://api.ipinfodb.com/v2/ip_query.php?key=' + ipinfodbkey + '&ip=' + ip + '&timezone=false').getroot()
            lon = root.find("Longitude").text
            lat = root.find("Latitude").text
            city = root.find("City").text
            long_url = "http://maps.google.com/maps?f=d&source=s_d&saddr=%s,%s" % (lat, lon)
            short_url = urlshortener.shorten(long_url)
            msg = "City: %s. Map: %s" % (city, short_url)
    except:
        msg = "DAMN YOU MITHORIUM"
    connection.privmsg(reply, msg)