-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/twitter post metrics #135
Conversation
python_callable=udfs.save_twitter_posts_and_insights, | ||
) | ||
|
||
CREATE_TABLE_IF_NEEDED >> SAVE_TWITTER_POSTS_AND_INSIGHTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
new_posts = [ | ||
post | ||
for post in posts | ||
if post["timestamp"] > last_post["created_at"].timestamp() | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
|
||
def request_posts_data() -> List[dict]: | ||
url = "https://twitter154.p.rapidapi.com/user/tweets" | ||
# 499339900 is PyConTW's twitter id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
# 499339900 is PyConTW's twitter id | ||
querystring = { | ||
"username": "pycontw", | ||
"user_id": "96479162", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the user id diff to the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
if response.ok: | ||
return response.json()["results"] | ||
raise RuntimeError(f"Failed to fetch posts data: {response.text}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
bigquery.SchemaField("created_at", "TIMESTAMP", mode="REQUIRED"), | ||
bigquery.SchemaField("message", "STRING", mode="REQUIRED"), | ||
], | ||
write_disposition="WRITE_APPEND", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
client = bigquery.Client(project=os.getenv("BIGQUERY_PROJECT")) | ||
sql = """ | ||
SELECT | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to me that we only need created at
? Querying less field can save us money
Types of changes
Description
A new DAG for scraping Twitter post and insights data.
Checklist:
poetry run pytest
locally to ensure all linter checks pass