Esempio n. 1
0
def load(request):
    ###load twitter ####

    url = "http://api.twitter.com/1/trends/2450022.json"
    req = urllib2.Request(url)
    req.add_header('User-Agent', 'Safari 3.2')
    response = urllib2.urlopen(req)
    output_json = json.load(response)
    for x in output_json:
        for y in x['trends']:
            s = Trend.get_or_insert(y['name'],
                                    title=y['name'],
                                    source="twitter")

    ###laod Google ####
    gurl = "http://www.google.com/trends/hottrends/atom/hourly"
    data = urllib2.urlopen(gurl)

    tree = ET.parse(data)
    root = tree.getroot()

    for child in root:
        grandchildren = child.getchildren()
        for grandchild in grandchildren:
            if grandchild.text:
                soup = BeautifulSoup(grandchild.text)
                hottrends = []
                for ht in soup('li'):
                    gkeyword = ht.a.string
                    s = Trend.get_or_insert(gkeyword,
                                            title=str(gkeyword),
                                            source="google")

    return HttpResponse("loaded twitter and google")
Esempio n. 2
0
def load(request):
  ###load twitter ####
  
  url = "http://api.twitter.com/1/trends/2450022.json"
  req = urllib2.Request(url)
  req.add_header('User-Agent', 'Safari 3.2')
  response = urllib2.urlopen(req)
  output_json = json.load(response)
  for x in output_json:
      for y in x['trends']:
         s = Trend.get_or_insert(y['name'], title=y['name'],source="twitter")




  ###laod Google ####
  gurl = "http://www.google.com/trends/hottrends/atom/hourly"
  data =urllib2.urlopen(gurl)

  tree = ET.parse(data)
  root = tree.getroot()
     

  for child in root:      
        grandchildren = child.getchildren() 
        for grandchild in grandchildren:
            if grandchild.text:           
             soup = BeautifulSoup(grandchild.text)
             hottrends = []          
             for ht in soup('li'):
                  gkeyword = ht.a.string
                  s = Trend.get_or_insert(gkeyword, title=str(gkeyword),source="google")
                  


  return HttpResponse("loaded twitter and google")