Python tweepy trends and tweets

1

I have the following code to get trends and show me the tweets that have been made from Madrid

trends1 = api.trends_place(1)
trends = set([trend['name'] for trend in trends1[0]['trends']])
print trends

but when executing it, it brings out all this paragraph, inside the trends are found but for some reason I get all that junk code

set([u'#\uc774\uc0ac\ub78c_\uc5f0\uc131\ubd84\uc704\uae30_\ubd04\uc5ec\ub984\uac00\uc744\uaca8\uc6b8', u'#\u0645\u062c\u0644\u0633_\u0627\u0644\u0627\u0645\u0647_2016', u'Diego Costa', u'#PBBLuckyBunnyElisse', u'#\u771f\u7530\u4e38', u'#azfey', u'Ander Herrera', u'#\u0627\u0645_\u0628\u064a_\u0633\u064a_\u0628\u0631\u0648_\u062a\u062d\u0627\u0631\u0628_\u0627\u0644\u0646\u0635\u0631', u'#Gentiloni', u'#KMJSWhiteChristmas', u'#inmezzora', u'#\u0647\u062f\u064a\u062a\u064a_\u0631\u0648\u0627\u062a\u0631_\u0647\u0648\u0627\u0648\u064a_\u0627\u0644\u062c\u062f\u064a\u062f', u'\u73fe\u4f4f\u6240', u'#EXO100thCONCERT', u'#SundayMorning', u'#\u4e43\u6728\u5742\u5de5\u4e8b\u4e2d', u'#\u0635\u0648\u062a_\u062a\u062d\u0628\u0647_\u062d\u064a\u0644', u'#BoybandPHWinners', u'Mandzukic', u'#PolisiminYan\u0131nday\u0131m', u'\u7fbd\u751f\u304f\u3093', u'#OLSRFC', u'#Kans\u0131zVatans\u0131zlar', u'#MeDesperteTempranoY', u'#HappySeungriDay', u'#CagliariNapoli', u'#VoiceIndiaS2', u'#\u3069\u3046\u3067\u3082\u3044\u3044\u500b\u4eba\u60c5\u5831\u3092\u6652\u305d\u3046', u'#\u0648\u064a\u0646_\u0637\u0627\u0631\u062a_\u0641\u0644\u0648\u0633\u0643', u'#Halk\u0131nG\xfcc\xfcTer\xf6r\xfcdeYenecek', u'#TorinoJuve', u'#\u304f\u3068\u6253\u3063\u3066\u30af\u30ea\u30b9\u30de\u30b9\u306a\u3089\u30ea\u30a2\u5145', u'#\u0627\u0644\u0643\u0627\u062a\u062f\u0631\u0627\u064a\u064a\u0647', u'#anisama', u'#\ub098\ub97c_\uc624\ud504\uc5d0\uc11c_\ubcf8_\ud6c4\uae30', u'#FelizDomingo', u'\u30a8\u30ad\u30b7\u30d3\u30b7\u30e7\u30f3', u'#MevlidKandili', u'#BadAdviceForTheHeartbroken', u'\uc5ec\uc911\uc0dd', u'#WeLoveTommos', u'#BMGM05', u'#GGVTropaGoals', u'#MUNTOT', u'#\u0632\u062f_\u0631\u0635\u064a\u062f\u064357', u'Tati Quebra Barraco', u'#\u0645\u0633\u0644\u0645_\u0645\u0633\u064a\u062d\u064a_\u0627\u064a\u062f_\u0648\u062d\u062f\u0647', u'Belotti', u'#enacional', u'#DomingoDetremuraSDV'])

How can I get him to show me something like that?

1-trend ---- 1000 tweets

2-trend ----- 23423 tweet

    
asked by 11.12.2016 в 16:29
source

1 answer

1

First, what you are currently delivering is correct and it is not garbage, it is encoded in unicode , so characters that are not represented in ASCII are usually written as \uxx (As characters Chinese, lyrics with tilde, etc).

Based on the Twitter API ( link ). The method you are using to get trends by area only provides the following information:

[
  {
    "as_of": "2012-08-24T23:25:43Z",
    "created_at": "2012-08-24T23:24:14Z",
    "locations": [
      {
        "name": "Worldwide",
        "woeid": 1
      }
    ],
    "trends": [
      {
        "events": null,
        "name": "#GanaPuntosSi",
        "promoted_content": null,
        "query": "%23GanaPuntosSi",
        "url": "http://twitter.com/search/?q=%23GanaPuntosSi"
      },
    ...
  ]
 }
[

With this call you can basically only know the name of the Trending Topic and its URL.

Therefore, with this call you can not know the amount of Tweets that make up a Trend. Moreover, it is difficult to respond to this query since you would have to set the start and end date of a hashtag to be able to count the number of Tweets issued in that period with that keyword.

Note that a hashtag can not appear and disappear, since Tweets containing that keyword can exist since Twitter appeared. Even before the word became Trending Topic. Therefore, asking the question of how many Tweets a Trend has is more complex than it seems.

Unfortunately Twitter does not provide a way to access historical Tweets (Issued long ago) so this type of query would be difficult to answer with the official API.

If it is so important to count the number of Tweets issued with a keyword , I recommend you look for other libraries that do not use the official Twitter API, if not exploit the search system to be able to make inquiries about specific periods of time containing keywords , such as the Trending topic you want to analyze.

    
answered by 12.12.2016 в 01:42