/twitter-summarizer-rest-service-PupilTong

twitter-summarizer-rest-service-PupilTong created by GitHub Classroom

Primary LanguagePython

Twitter hashtag photo video summary generator - Restful Api Version

Feel CRAZY about the FOOLISH CORS POLICY AND NGINX MANUAL

use

add_header Access-Control-Allow-Origin '*' always;

TO ADD A 'ALLOW ALL' Header on your response

like this:

server {

        server_name hw5.onic.xyz;
        location / {
        add_header Access-Control-Allow-Origin '*' always;
        proxy_pass http://127.0.0.1:6666;
        proxy_http_version 1.1;
        proxy_set_header   Host $host;
        proxy_set_header Content-Type 'application/json';
        }

listen 80;
}

AND DONT FORGET ADDING 'always' IN THE END

Offical and popular instructions never told u.

requirement

python > 3.6

ffmpeg

Api Definition

Start a task

curl -i -H "Content-Type: application/json" -X POST -d '{"keyword":"book"}' http://hw5.onic.xyz/

return

{
 "uuid": "3f3d3fb0-b175-4a58-b8ec-9923813d0505", 
 "get_status": "http://hw5.onic.xyz/status/3f3d3fb0-b175-4a58-b8ec-9923813d0505", 
 "get_video": "http://hw5.onic.xyz/video/3f3d3fb0-b175-4a58-b8ec-9923813d0505"
}

Check status

curl -i -X GET http://hw5.onic.xyz/status/3f3d3fb0-b175-4a58-b8ec-9923813d0505

return

{
 "uuid": "3f3d3fb0-b175-4a58-b8ec-9923813d0505", 
 "percentage": -1, 
 "status": "finished/doesnt exist"
}

Get Video

curl -i -X GET http://hw5.onic.xyz/video/3f3d3fb0-b175-4a58-b8ec-9923813d0505

return

file it self

Deployment Guide

Environment Configuration

git clone http://github.com/BUEC500C1/video-PupilTong.git
cd video-PupilTong
pip3 install -r requirements.txt
python3 rest.py

import your own Twitter API key info

Keys should be stores in 'key file:

[auth]
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""

Too Old;DR

Module ffmpegQueue.py

This module is able to convert a tuple of texts and a tuple of images' url to a summary video.

Architechture

Architechture

Class queueItem

One task of the work load pool

Constructor Parameters

Name Description type
directory Output video storage directory str
text List of texts tuple
img Images list for each text. Program will use the first as the background tuple
keyword keyword of this task, will use this to create a temp directory. Program will try to delete the directory first str

Class VideoApi

video processing core

Method AddTask

Name Description type
item the task to be added to the workload pool ququeItem
return

return a unique uuid of this task.

Method CheckStatus

Check current task status.

return

type: int

# 0 - unstart
# 1~99 - processing
# 100 - finished
# -1 - deleted

Module TwitterVideoSum.py

This module is able to pull tweets from twitter with provided parmeters and prepare data for Module ffmpegQueue

Architechture

Architechture

Class TwitterVideoSum:

Constructor

Name Description type
consumer_key twitter api key str
consumer_secret twitter api key str
access_token twitter api key str
access_token_secret twitter api key str
keywords List of hashtags tuple
directory video storage directory str
item number of photos for each hashtag to be converted str

Method Start

Start the process