This API can search the tweet information from twitter by hashtag or username.
No need authentication
If you want to use this API in local, please install the packages using pip or other package manager.
this application depends on the following libraries.
Library | version |
---|---|
flask | 1.0.2 |
flask_restful | 0.3.7 |
requests | 2.21.0 |
selenium | 3.141.0 |
chromedriver-binary | 73.0.3683.68.0 |
gunicorn | 19.9.0 |
Note: You have to download the chromedriver-binary which has same major version of your chrome browser. If you want to check the chrome browser version, you can check it in your browser
The following examples is using pip to install the dependencies.
- Install the Flask.
pip install flask
- Install the flask_restful
pip install flask_restful
- Install the requests
pip install requests
- Install the selenium
pip install selenium
- Install the chromedriver-binary
pip install chromedriver-binary=="{Your Chrome version}"
- Install the gunicorn
pip install gunicorn
- Create the clone of project from github.
git clone https://github.com/kigamittsu/scrape_twitter.git
- Run the server
cd ~/scrape_twitter
gunicorn server:app
- Now you can call this API.
- Run the server
gunicorn server:app
- Run the test
python -m unittest tests.test_api
Get the tweets information which has target hashtag name
Resource | Description |
---|---|
hashtagname | Target hashtag name |
Request Parameter | Type | Description |
---|---|---|
limit (Optional) | Integer | Specifies the number of tweets to retrieve, the default is 30 |
Get the tweets information which has target user name
Resource | Description |
---|---|
username | Target user name |
Request Parameter | Type | Description |
---|---|---|
limit (Optional) | Integer | Specifies the number of tweets to retrieve, the default is 30 |
If you want to test this API, we highly recommend to use the Postman or Insomnia
Sample requests of /hashtags/{hashtagname}
http://127.0.0.1:8000/hashtags/twitter?limit=20
Sample requests of /users/{username}
http://127.0.0.1:8000/users/twitter?limit=20
[
{
"account": {
"fullname": "foo bar",
"href": "https://twitter.com/foobar",
"user_id": "342384"
},
"date": "16:23 - 2019年5月15日",
"hashtags": [
"#Twitter"
],
"text": "Sample text",
"likes": 10,
"replies": 4,
"retweets": 5
},
...
]
- Improve response speed (more quick)
- Add other endpoints
- Write more test
This project is licensed under the MIT License