jdfoote / intro-to-programming-and-data-science Goto Github PK
View Code? Open in Web Editor NEWMaterials for COM 67400 taught at Purdue University
Materials for COM 67400 taught at Purdue University
This repository contains materials for my Introduction to Programming and Data Science course at Purdue University. The syllabus for the course can be found at https://wiki.communitydata.science/Intro_to_Programming_and_Data_Science_(Summer_2021)
Dear, I have the Academic Research Access Application Approved.
I am getting errors in both codes:
Forbidden Traceback (most recent call last)
in ()
1 hoax_tweets = []
2 for response in tweepy.Paginator(client.search_all_tweets,
----> 3 query = 'COVID'):
4 # user_fields = ['username', 'public_metrics', 'description', 'location'],
5 # tweet_fields = ['created_at', 'geo', 'public_metrics', 'text'],
3 frames
/usr/local/lib/python3.7/dist-packages/tweepy/client.py in request(self, method, route, params, json, user_auth)
122 raise Unauthorized(response)
123 if response.status_code == 403:
--> 124 raise Forbidden(response)
125 # Handle 404?
126 if response.status_code == 429:
Forbidden: 403 Forbidden
Exception Traceback (most recent call last)
in ()
58
59
---> 60 main()
2 frames
in connect_to_endpoint(url, headers, params, next_token)
24 print(response.status_code)
25 if response.status_code != 200:
---> 26 raise Exception(response.status_code, response.text)
27 return response.json()
28
Exception: (403, '{"client_id":"23021128","detail":"When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.","registration_url":"https://developer.twitter.com/en/docs/projects/overview","title":"Client Forbidden","required_enrollment":"Standard Basic","reason":"client-not-enrolled","type":"https://api.twitter.com/2/problems/client-forbidden"}')
Any suggestion, please?
Dear Foote,
I try to associate the place info with the tweet, just like the user info. But I get an error.
The sections I made changes and the line I got an error on are as follows. Thanks a lot.
client = tweepy.Client(bearer_token, wait_on_rate_limit=True) hoax_tweets = [] for response in tweepy.Paginator(client.search_all_tweets, query = 'deprem lang:tr', user_fields = ['id', 'name', 'username', 'public_metrics', 'description', 'location', 'verified'], tweet_fields = ['id', 'created_at', 'geo', 'public_metrics', 'text'], place_fields = ['full_name','place_type'], expansions = ['author_id', 'geo.place_id'], start_time = '2023-01-14T00:00:00Z', end_time = '2023-01-15T00:00:00Z', max_results=500): time.sleep(1) hoax_tweets.append(response)
`result = []
user_dict = {}
place_dict = {}
for response in hoax_tweets:
# Take all of the users, and put them into a dictionary of dictionaries with the info we want to keep
for user in response.includes['users']:
user_dict[user.id] = {'username': user.username,
'name': user.name,
'followers': user.public_metrics['followers_count'],
'tweets': user.public_metrics['tweet_count'],
'description': user.description,
'location': user.location,
'verified': user.verified
}
for place in response.includes['places']:
place_dict[place.id] = {'full_name': place.full_name,
'place_type': place.place_type
}
for tweet in response.data:
# For each tweet, find the author's information
author_info = user_dict[tweet.author_id]
# For each tweet, find the places information
place_info = place_dict[tweet.place_id] #**Error Line**
# Put all of the information we want to keep in a single dictionary for each tweet
result.append({'author_id': tweet.author_id,
'username': author_info['username'],
'author_followers': author_info['followers'],
'author_tweets': author_info['tweets'],
'author_description': author_info['description'],
'author_location': author_info['location'],
'text': tweet.text,
'created_at': tweet.created_at,
'retweets': tweet.public_metrics['retweet_count'],
'replies': tweet.public_metrics['reply_count'],
'likes': tweet.public_metrics['like_count'],
'quote_count': tweet.public_metrics['quote_count'],
'tweet_id': tweet.id,
'author_name': author_info['name'],
'verified': author_info['verified'],
'full_name': place_info['full_name'],
'place_type': place_info['place_type']
})`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.