Mini Project 1 and Mini Project 3 of EC601 class from Boston University.
This API uses Tweepy to download images from a Twitter account,uses GoogleVision to label images and finally uses ffmpeg to make images to a video. These python files belong to Mini Project 1:
- test_tweepy.py
- rename.py
- vision.py
- main.py Run main.py to use the API. The images downloaded from Twitter account will store on your PC. The output video is test.avi.
Use database to store image information and log. Both SQL(MySQL) and NoSQL(MongoDB) are implemented. In mini project 3, the functions and files are reorganzied and fine-tuned. Also, more exceptions are considered. These python files belong to Mini Project 3:
- twitter_api.py
- test.py Run test.py to use the API. The images downloaded from Twitter account will store on your PC. The output video is test.avi. Logs and image information are stored in database.
In order to successfully use the API, these packages should be installed first:
- Tweepy
pip install tweepy
- wget
pip install wget
- FFmpeg
You can download FFmpeg from official website: http://ffmpeg.org/
- GoogleVision
pip install google-cloud-vision
- PyMySQL
pip install pymysql
- PyMongo
pip install pymongo
Please make sure MySQL and MongoDB are successfully installed on your PC.
-
MongoDB: https://www.mongodb.com/
- Create a new database
CREATE DATABASE Twitter_API;- Create new tables
(1) api_log
CREATE TABLE api_log(
log_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
time DATETIME,
action VARCHAR(50));(2) img_info
CREATE TABLE img_info(
label_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
twitter_id VARCHAR(50),
label VARCHAR(50),
time DATETIME NULL,
img_url VARCHAR(200));You can skip this step because the API will automatically create a new database in MongoDB.
You need to provide your own keys and secrets in test.py, line 3 to 6.
consumer_key = 'Your consumer key'
consumer_secret = 'Your consumer secrets'
access_key = 'Your access key'
access_secret = 'Your access secrets'You need to put your Google Vision key file under the project folder.
You need to make sure that the MySQL configuration is correct. You can modify it in twitter_api.py, line 27 to 31.
self.mysql = pymysql.connect(host='localhost',
user='root',
password='your password',
db='Twitter_API',
port=3306)- Twitter account In test.py, line 8, you can set the twitter account that you want to download images from.
- Number of images In test.py, line 9, you can set the number of images that you want to download.
- Keyword In test.py, line 23, you can set the search keyword.