I'm trying to extract the emails from all Google Calendar events. I've been following other links (Google Calendar API how to find attendee list) but I'm getting an error
attendees = event['attendees'].get('email', event['attendees'].get('email'))
AttributeError: 'list' object has no attribute 'get'
This is the code
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
end = event['end'].get('dateTime', event['end'].get('date'))
attendees = event['attendees'].get('email', event['attendees'].get('email'))
print(attendees)
You can't call get() on a list which I'm guessing event['attendees'] is. You have multiple way of handling this. You can loop through the event['attendees'] and get the email from each individual attendee. You could also use map() to do the same thing
forEach Loop example:
event['attendees'].forEach(attendee => console.log(attendee.get('email')))
map example:
const attendees = event['attendees'].map(attendee => attendee.get('email'))
Related
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
I have code to look up events but keep getting an error:
File "facebook_events.py", line 8, in
events = graph.request('/search?q=Poetry&type=event')
File "/Users/teomeyerhoff/Desktop/projects/jakecongress/facebookenv/lib/python3.7/site-packages/facebook/init.py", line 313, in request
raise GraphAPIError(result)
facebook.GraphAPIError: (#33) This object does not exist or does not support this action.
Has something changed in Facebooks api. It looks as though I can no longer access events using the query string: '/search?q=Poetry&type=event' as a graph request.
import urllib3
import facebook
import requests
token = "EA......" //not actual token
graph = facebook.GraphAPI(access_token=token, version = "2.8")
events = graph.request('/search?q=Poetry&type=event')
print(events)
eventList = events['data']
eventid = eventList[1]['id']
event1 = graph.get_object(id=eventid, fields='attending_count, can_guests_invite, \
category, cover, declined_count, description, \
end_time, guest_list_enabled, interested_count, \
is_canceled, is_page_owned, is_viewer_admin, \
maybe_count, noreply_count, owner, parent_group,\
place, ticket_uri, timezone, type, updated_time')
attenderscount = event1['attending_count']
declinerscount = event1['declined_count']
interestedcount = event1['interested_count']
maybecount = event1['maybe_count']
noreplycount = event1['noreply_count']
attenders = requests.get('https://graph.facebook.com/v2.8/"+eventid+"\
/attending?access_token="+token+"&limit='+str(attenderscount))
attenders_json = attenders.json()
admins = requests.get("https://graph.facebook.com/v2.8/"+eventid+"\
/admins?access_token="+token)
admins_json = admins.json()
Thank you for the help.
It looks as though I can no longer access events using the query string: '/search?q=Poetry&type=event' as a graph request.
Yes, that is the case.
https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#search-4-4
Search API
You can no longer use the /search endpoint with the following object types:
event
group
page
user
Also mentioned in the accompanying blog post, https://developers.facebook.com/blog/post/2018/04/04/facebook-api-platform-product-changes/
Search API
Deprecated:
Support for finding pages, groups, events, users using search.
I need your help to order listed item.
I am trying to make apps that can send message to his/her friends ( just like social feeds ). After watching Bret Slatkin talk about create microblogging here's my code:
class Message(ndb.Model):
content = ndb.TextProperty()
created = ndb.DateTimeProperty(auto_now=True)
class MessageIndex(ndb.Model):
receivers = ndb.StringProperty(repeated=True)
class BlogPage(Handler):
def get(self):
if self.request.cookies.get("name"):
user_loggedin = self.request.cookies.get("name")
else:
user_loggedin = None
receive = MessageIndex.query(MessageIndex.receivers == user_loggedin)
receive = receive.fetch()
message_key = [int(r.key.parent().id()) for r in receive]
messages = [Message.get_by_id(int(m)) for m in message_key]
for message in messages:
self.write(message)
The first I do a query to get all message that has my name in the receivers. MessageIndex is child of Message, then I can get key of all message that I receive. And the last is I iter get_by_id using list of message key that I get.
This works fine, but I want to filter each message by its created datetime and thats the problem. The final output is listed item, which cant be ordered using .order or .filter
Maybe some of you can light me up.
You can use the message keys in an 'IN' clause in the Message query. Note that you will need to use the parent() key value, not the id() in this case.
eg:
# dtStart, dtEnd are datetime values
message_keys = [r.key.parent() for r in receive]
query = Message.query(Message._key.IN(message_keys), Message.created>dtStart, Message.created<dtEnd)
query = query.order(Message.created) # or -Message.created for desc
messages = query.fetch()
I am unsure if you wish to simply order by the Message created date, or whether you wish to filter using the date. Both options are catered for above.
I want to use Python Facepy to fetch the events from our company Facebook site.The strange thing is that everything works fine, except the event description is missing in returned data:
from facepy import GraphAPI
graph = GraphAPI("mysecrettoken")
events = graph.get('ourcompany/events')
for x in events['data']:
print x['description']
KeyError: 'description'
Except description, all data is there (name, start_time) etc etc
The event description isn't provided by the Graph api. I have to fetch it seperately for every event.
I have a problem with google calendar api.
How can you select which calendar to add an event? It add always to default calendar?
thanks
You can list the calendars using the GetOwnCalendarsFeed() and GetAllCalendarsFeed() calls. This will return a list of entries, each of which holds attributes for a given calendar. You need to obtain the calendar's url from the entry.content.src attribute, and use this on your InsertEntry call:
client = calendar.service.CalendarService(email='x', password='y')
feed = client.GetOwnCalendarsFeed()
# map the 'title' -> 'url'
urls = dict((e.title.text, e.content.src) for e in feed.entry)
client.InsertEvent(event, urls['My Calendar'])