I am scraping news feed from a twitter user timeline. I would like to get only the feeds posted in the last 24hours. I am using TwitterSearch library and specifically using TwitterUserOrder to have access to a user timeline. However, I cannot use 'set_until' and get ALL the tweets of the timeline.
'set_until' works for TwitterSearchOrder, and not 'TwitterUserOrder' which is weird.
I get this error :
AttributeError: 'TwitterUserOrder' object has no attribute 'set_until'
Anyone has the same issue ?
import datetime as DT
from TwitterSearch import TwitterUserOrder
today = DT.date.today()
days_ago = today - DT.timedelta(days=1)
tuo = TwitterUserOrder('SnowflakeDB')
tuo.set_include_entities(False)
tuo.set_until(days_ago)
tuo.arguments.update({'tweet_mode':'extended'})
tuo.arguments.update({'truncated': 'False' })`
Related
I am trying to learn sentiment analysis using vaderSentiment. For some reason, the when I create a query, I am getting the above error. I've checked the documentation, and there is no mention of a Utc attribute being required. Here is the basic code I am using:
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import twint
analyzer = SentimentIntensityAnalyzer()
c = twint.Config()
c.Search = "Tesla"
c.Store_object = True
c.Since = "2023-01-20"
twint.run.Search(c)
for tweet in twint.output.tweets_list:
print(tweet.tweet)
scores = analyzer.polarity_scores(tweet.tweet)
print(scores)
I've had a great deal of issues trying to get twint to work with my system, so it's highly probable I've not installed it correctly.
I want to develop a Jupyter Notebook which on executing every time shows the top 10 Twitter trending topics in India in the last 24 hours.
I got everything set up
auth = tweepy.OAuthHandler(apikey,apisecretkey)
auth.set_access_token(accesskey,accesssecret)
api = tweepy.API(auth)
and when I run trends1 = api.trends_place(23424848), it gives a AttributeError: 'API' object has no attribute 'trends_place'
And if this attribute has been removed then what should I do to get my work done Please help..
You are getting this error because api do not have this trends_place attribute.
If u check the documentation (https://docs.tweepy.org/en/stable/api.html#trends), you will see that instead of using api.trends_place(), the correct syntax is api. followed by the attribute get_place_trends().
So, i suggest the following code to get the desired result:
auth = tweepy.OAuthHandler(apikey,apisecretkey)
auth.set_access_token(accesskey,accesssecret)
api = tweepy.API(auth)
WOEID = 23424848
top_trends = api.get_place_trends(WOEID)
Note that top_trends is an dictionary inside a list of length 1. Treat it like top_trends[0]['trends'] and so on to get specific values. Example:
top_trends[0]['trends'][0]['name']
top_trends[0]['trends'][0]['url']
top_trends[0]['trends'][0]['promoted_content']
top_trends[0]['trends'][0]['query']
top_trends[0]['trends'][0]['tweet_volume']
To get trending topics near a specific location on Twitter,
Once you've set up:
auth = tweepy.OAuthHandler(apikey,apisecretkey)
auth.set_access_token(accesskey,accesssecret)
api = tweepy.API(auth)
use trends = api.trends_place(WOEID) to get the 50 trending topics based on the lWOEID
So I have this code (obviously purposely hiding the tokens)
import tweepy
consumerkey=''
consumerkeysecret=''
bearer=''
access=''
access_secret=''
auth = tweepy.AppAuthHandler(consumerkey, consumerkeysecret)
api = tweepy.API(auth,wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
tweet='1314271994054152192'
status = api.get_status(tweet,tweet_mode='extended')
print(status.screen_name)
print(status.location)
I'm learning Tweepy and so I used a tweet from Obama to test the features of the API. For whatever reason, I can't get the screen name or location for the tweet, as it says 'Status' object has no attribute 'location'. When I look at the json from printing out all the information about the tweet, both 'location' and 'screen_name' are in there and have text associated with it. How can I get this information?
You need to access the User object inside the Status object:
print(status.user.screen_name)
print(status.user.location)
Beginner in python, pyRevit, and Revit API so my apologies if I'm phrasing my question poorly. Today I used pyRevit to develop a simple pushbutton tool that worked, and then after a few minutes stopped working without anything being changed (that I'm aware of)
My tool adds all groups with excluded elements to the selection. It worked perfectly for a time, then started throwing this error, which I can't make heads or tails of:
Exception: The input argument "document" of function `anonymous-namespace'::FilteredElementCollector_constructor or one item in the collection is null at line 326 of file d:\ship\2018_px64\source\revit\revitdbapi\APIFilteredElementCollectorProxy.cpp. Parameter name: document
The path in the error message isn't one I recognize on my computer. Here's the relevant code (the traceback goes to line 24, which is "groups = FilteredElementCollector...":
from pyrevit import script
from pyrevit.framework import List
from pyrevit.framework import clr
from pyrevit import revit, DB
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
groups = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_IOSModelGroups).WhereElementIsNotElementType().ToElements()
selection = revit.get_selection()
SelectionIds = []
for group in groups:
name = group.Name
if "(members excluded)" in name:
SelectionIds.append(group.Id)
selection.set_to(SelectionIds)
Thanks a lot for any solutions, or even help deciphering the error message.
I'm brand new at Python and I'm trying to write an extension to an app that imports GA information and parses it into MySQL. There is a shamfully sparse amount of infomation on the topic. The Google Docs only seem to have examples in JS and Java...
...I have gotten to the point where my user can authenticate into GA using SubAuth. That code is here:
import gdata.service
import gdata.analytics
from django import http
from django import shortcuts
from django.shortcuts import render_to_response
def authorize(request):
next = 'http://localhost:8000/authconfirm'
scope = 'https://www.google.com/analytics/feeds'
secure = False # set secure=True to request secure AuthSub tokens
session = False
auth_sub_url = gdata.service.GenerateAuthSubRequestUrl(next, scope, secure=secure, session=session)
return http.HttpResponseRedirect(auth_sub_url)
So, step next is getting at the data. I have found this library: (beware, UI is offensive) http://gdata-python-client.googlecode.com/svn/trunk/pydocs/gdata.analytics.html
However, I have found it difficult to navigate. It seems like I should be gdata.analytics.AnalyticsDataEntry.getDataEntry(), but I'm not sure what it is asking me to pass it.
I would love a push in the right direction. I feel I've exhausted google looking for a working example.
Thank you!!
EDIT: I have gotten farther, but my problem still isn't solved. The below method returns data (I believe).... the error I get is: "'str' object has no attribute '_BecomeChildElement'" I believe I am returning a feed? However, I don't know how to drill into it. Is there a way for me to inspect this object?
def auth_confirm(request):
gdata_service = gdata.service.GDataService('iSample_acctSample_v1.0')
feedUri='https://www.google.com/analytics/feeds/accounts/default?max-results=50'
# request feed
feed = gdata.analytics.AnalyticsDataFeed(feedUri)
print str(feed)
Maybe this post can help out. Seems like there are not Analytics specific bindings yet, so you are working with the generic gdata.
I've been using GA for a little over a year now and since about April 2009, i have used python bindings supplied in a package called python-googleanalytics by Clint Ecker et al. So far, it works quite well.
Here's where to get it: http://github.com/clintecker/python-googleanalytics.
Install it the usual way.
To use it: First, so that you don't have to manually pass in your login credentials each time you access the API, put them in a config file like so:
[Credentials]
google_account_email = youraccount#gmail.com
google_account_password = yourpassword
Name this file '.pythongoogleanalytics' and put it in your home directory.
And from an interactive prompt type:
from googleanalytics import Connection
import datetime
connection = Connection() # pass in id & pw as strings **if** not in config file
account = connection.get_account(<*your GA profile ID goes here*>)
start_date = datetime.date(2009, 12, 01)
end_data = datetime.date(2009, 12, 13)
# account object does the work, specify what data you want w/
# 'metrics' & 'dimensions'; see 'USAGE.md' file for examples
account.get_data(start_date=start_date, end_date=end_date, metrics=['visits'])
The 'get_account' method will return a python list (in above instance, bound to the variable 'account'), which contains your data.
You need 3 files within the app. client_secrets.json, analytics.dat and google_auth.py.
Create a module Query.py within the app:
class Query(object):
def __init__(self, startdate, enddate, filter, metrics):
self.startdate = startdate.strftime('%Y-%m-%d')
self.enddate = enddate.strftime('%Y-%m-%d')
self.filter = "ga:medium=" + filter
self.metrics = metrics
Example models.py: #has the following function
import google_auth
service = googleauth.initialize_service()
def total_visit(self):
object = AnalyticsData.objects.get(utm_source=self.utm_source)
trial = Query(object.date.startdate, object.date.enddate, object.utm_source, ga:sessions")
result = service.data().ga().get(ids = 'ga:<your-profile-id>', start_date = trial.startdate, end_date = trial.enddate, filters= trial.filter, metrics = trial.metrics).execute()
total_visit = result.get('rows')
<yr save command, ColumnName.object.create(data=total_visit) goes here>