mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Get user tweets (#5593)
* updating DIRECTORY.md * Create get_user_tweets.py * updating DIRECTORY.md * Reformat code with black * Add argument type * Add return type * Add tweepy * Fix isort issues * Fix flake8 issues * WIP: doctest * Doctest setup and format with pre-commit * Remove doctests * Update web_programming/get_user_tweets.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update get_user_tweets.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
8e857e8692
commit
f93c7d4d80
10
DIRECTORY.md
10
DIRECTORY.md
@ -10,6 +10,11 @@
|
||||
* [Newton Raphson](https://github.com/TheAlgorithms/Python/blob/master/arithmetic_analysis/newton_raphson.py)
|
||||
* [Secant Method](https://github.com/TheAlgorithms/Python/blob/master/arithmetic_analysis/secant_method.py)
|
||||
|
||||
## Audio Filters
|
||||
* [Butterworth Filter](https://github.com/TheAlgorithms/Python/blob/master/audio_filters/butterworth_filter.py)
|
||||
* [Iir Filter](https://github.com/TheAlgorithms/Python/blob/master/audio_filters/iir_filter.py)
|
||||
* [Show Response](https://github.com/TheAlgorithms/Python/blob/master/audio_filters/show_response.py)
|
||||
|
||||
## Backtracking
|
||||
* [All Combinations](https://github.com/TheAlgorithms/Python/blob/master/backtracking/all_combinations.py)
|
||||
* [All Permutations](https://github.com/TheAlgorithms/Python/blob/master/backtracking/all_permutations.py)
|
||||
@ -60,6 +65,7 @@
|
||||
* [Base64 Encoding](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base64_encoding.py)
|
||||
* [Base85](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base85.py)
|
||||
* [Beaufort Cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/beaufort_cipher.py)
|
||||
* [Bifid](https://github.com/TheAlgorithms/Python/blob/master/ciphers/bifid.py)
|
||||
* [Brute Force Caesar Cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/brute_force_caesar_cipher.py)
|
||||
* [Caesar Cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/caesar_cipher.py)
|
||||
* [Cryptomath Module](https://github.com/TheAlgorithms/Python/blob/master/ciphers/cryptomath_module.py)
|
||||
@ -106,8 +112,8 @@
|
||||
|
||||
## Conversions
|
||||
* [Binary To Decimal](https://github.com/TheAlgorithms/Python/blob/master/conversions/binary_to_decimal.py)
|
||||
* [Binary To Octal](https://github.com/TheAlgorithms/Python/blob/master/conversions/binary_to_octal.py)
|
||||
* [Binary To Hexadecimal](https://github.com/TheAlgorithms/Python/blob/master/conversions/binary_to_hexadecimal.py)
|
||||
* [Binary To Octal](https://github.com/TheAlgorithms/Python/blob/master/conversions/binary_to_octal.py)
|
||||
* [Decimal To Any](https://github.com/TheAlgorithms/Python/blob/master/conversions/decimal_to_any.py)
|
||||
* [Decimal To Binary](https://github.com/TheAlgorithms/Python/blob/master/conversions/decimal_to_binary.py)
|
||||
* [Decimal To Binary Recursion](https://github.com/TheAlgorithms/Python/blob/master/conversions/decimal_to_binary_recursion.py)
|
||||
@ -352,6 +358,7 @@
|
||||
* [Multi Heuristic Astar](https://github.com/TheAlgorithms/Python/blob/master/graphs/multi_heuristic_astar.py)
|
||||
* [Page Rank](https://github.com/TheAlgorithms/Python/blob/master/graphs/page_rank.py)
|
||||
* [Prim](https://github.com/TheAlgorithms/Python/blob/master/graphs/prim.py)
|
||||
* [Random Graph Generator](https://github.com/TheAlgorithms/Python/blob/master/graphs/random_graph_generator.py)
|
||||
* [Scc Kosaraju](https://github.com/TheAlgorithms/Python/blob/master/graphs/scc_kosaraju.py)
|
||||
* [Strongly Connected Components](https://github.com/TheAlgorithms/Python/blob/master/graphs/strongly_connected_components.py)
|
||||
* [Tarjans Scc](https://github.com/TheAlgorithms/Python/blob/master/graphs/tarjans_scc.py)
|
||||
@ -978,6 +985,7 @@
|
||||
* [Fetch Jobs](https://github.com/TheAlgorithms/Python/blob/master/web_programming/fetch_jobs.py)
|
||||
* [Get Imdb Top 250 Movies Csv](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_imdb_top_250_movies_csv.py)
|
||||
* [Get Imdbtop](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_imdbtop.py)
|
||||
* [Get User Tweets](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_user_tweets.py)
|
||||
* [Giphy](https://github.com/TheAlgorithms/Python/blob/master/web_programming/giphy.py)
|
||||
* [Instagram Crawler](https://github.com/TheAlgorithms/Python/blob/master/web_programming/instagram_crawler.py)
|
||||
* [Instagram Pic](https://github.com/TheAlgorithms/Python/blob/master/web_programming/instagram_pic.py)
|
||||
|
@ -14,5 +14,6 @@ sklearn
|
||||
statsmodels
|
||||
sympy
|
||||
tensorflow
|
||||
tweepy
|
||||
types-requests
|
||||
xgboost
|
||||
|
60
web_programming/get_user_tweets.py
Normal file
60
web_programming/get_user_tweets.py
Normal file
@ -0,0 +1,60 @@
|
||||
import csv
|
||||
|
||||
import tweepy
|
||||
|
||||
# Twitter API credentials
|
||||
consumer_key = ""
|
||||
consumer_secret = ""
|
||||
access_key = ""
|
||||
access_secret = ""
|
||||
|
||||
|
||||
def get_all_tweets(screen_name: str) -> None:
|
||||
|
||||
# authorize twitter, initialize tweepy
|
||||
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
|
||||
auth.set_access_token(access_key, access_secret)
|
||||
api = tweepy.API(auth)
|
||||
|
||||
# initialize a list to hold all the tweepy Tweets
|
||||
alltweets = []
|
||||
|
||||
# make initial request for most recent tweets (200 is the maximum allowed count)
|
||||
new_tweets = api.user_timeline(screen_name=screen_name, count=200)
|
||||
|
||||
# save most recent tweets
|
||||
alltweets.extend(new_tweets)
|
||||
|
||||
# save the id of the oldest tweet less one
|
||||
oldest = alltweets[-1].id - 1
|
||||
|
||||
# keep grabbing tweets until there are no tweets left to grab
|
||||
while len(new_tweets) > 0:
|
||||
print(f"getting tweets before {oldest}")
|
||||
|
||||
# all subsiquent requests use the max_id param to prevent duplicates
|
||||
new_tweets = api.user_timeline(
|
||||
screen_name=screen_name, count=200, max_id=oldest
|
||||
)
|
||||
|
||||
# save most recent tweets
|
||||
alltweets.extend(new_tweets)
|
||||
|
||||
# update the id of the oldest tweet less one
|
||||
oldest = alltweets[-1].id - 1
|
||||
|
||||
print(f"...{len(alltweets)} tweets downloaded so far")
|
||||
|
||||
# transform the tweepy tweets into a 2D array that will populate the csv
|
||||
outtweets = [[tweet.id_str, tweet.created_at, tweet.text] for tweet in alltweets]
|
||||
|
||||
# write the csv
|
||||
with open(f"new_{screen_name}_tweets.csv", "w") as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(["id", "created_at", "text"])
|
||||
writer.writerows(outtweets)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# pass in the username of the account you want to download
|
||||
get_all_tweets("FirePing32")
|
Loading…
Reference in New Issue
Block a user