mirror of
https://github.com/thewesker/greptweet.git
synced 2025-12-20 12:11:05 -05:00
Dockerize
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
MAINTAINER Kai Hendry <hendry@iki.fi>
|
MAINTAINER Kai Hendry <hendry+greptweet@iki.fi>
|
||||||
|
|
||||||
RUN apk upgrade --update --available && \
|
RUN apk upgrade --update --available && \
|
||||||
apk add \
|
apk add \
|
||||||
@@ -21,9 +21,7 @@ ADD php-fpm.ini /etc/supervisor.d/php-fpm.ini
|
|||||||
ADD nginx.ini /etc/supervisor.d/nginx.ini
|
ADD nginx.ini /etc/supervisor.d/nginx.ini
|
||||||
|
|
||||||
RUN mkdir -p /srv/http/u
|
RUN mkdir -p /srv/http/u
|
||||||
VOLUME /srv/http/u/
|
RUN chmod -R 777 /srv/http/u
|
||||||
VOLUME /srv/http/
|
|
||||||
VOLUME /var/log/nginx
|
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
|
|||||||
7
Makefile
7
Makefile
@@ -10,11 +10,8 @@ build:
|
|||||||
docker build -t $(REPO) .
|
docker build -t $(REPO) .
|
||||||
|
|
||||||
start:
|
start:
|
||||||
docker run -d --name $(NAME) -v /mnt/2tb/greptweet/:/srv/http/u -v $(PWD)/www:/srv/http/ -v $(PWD)/logs:/var/log/nginx/ -p 81:80 $(REPO)
|
#docker run --rm -it --name $(NAME) -v /mnt/raid1/greptweet:/srv/http/u -v $(PWD)/www:/srv/http/ -v $(PWD)/logs:/var/log/nginx/ -p 81:80 $(REPO)
|
||||||
|
docker run --rm -it --name $(NAME) --env-file envfile -v /tmp/g:/srv/http/u -p 81:80 $(REPO)
|
||||||
stop:
|
|
||||||
docker stop $(NAME)
|
|
||||||
docker rm $(NAME)
|
|
||||||
|
|
||||||
sh:
|
sh:
|
||||||
docker exec -it $(NAME) /bin/sh
|
docker exec -it $(NAME) /bin/sh
|
||||||
|
|||||||
52
README.md
52
README.md
@@ -1,50 +1,20 @@
|
|||||||
# <http://greptweet.com>
|
# Greptweet
|
||||||
|
|
||||||
<a href="http://www.flickr.com/photos/hendry/7577182774/" title="Offline Greptweet on Chrome IOS by Kai Hendry, on Flickr"><img src="http://farm8.staticflickr.com/7133/7577182774_d5b654ea69_n.jpg" width="213" height="320" alt="Offline Greptweet on Chrome IOS"></a>
|
## Setup
|
||||||
|
|
||||||
* Image VIRTUAL SIZE <100MB (Docker)
|
Set `access_token` in envfile. You should be able to get it from [creating a new Twitter app](https://dev.twitter.com/apps/new).
|
||||||
* Uses [HTML offline feature](http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html)
|
|
||||||
* Aims to [suck less](http://suckless.org) by keeping lines of code low
|
|
||||||
* Can run from command line
|
|
||||||
* **Please** review and comment on the code!
|
|
||||||
|
|
||||||
# Known limitations
|
curl -X POST "https://api.twitter.com/oauth2/token" -d "grant_type=client_credentials" -u consumerKey:consumerSecret
|
||||||
|
|
||||||
* API only allows 3200 tweets to be downloaded this way at one time :(
|
echo 'access_token=secret' > envfile
|
||||||
* 300 API limit using a [Application only Auth](https://dev.twitter.com/docs/auth/application-only-auth) bearer token (which doesn't seem to expire...)
|
docker run -d --name greptweet --env-file envfile -p 8888:80 hendry/greptweet
|
||||||
* Won't work on protected accounts (duh!)
|
|
||||||
* No @mentions or DMs from other accounts
|
|
||||||
|
|
||||||
# API
|
# Maintenance
|
||||||
|
|
||||||
Invoke a fetch of a TWITTER_USERNAME by accessing the URL:
|
Running it again:
|
||||||
|
|
||||||
http://greptweet.com/f/TWITTER_USERNAME
|
docker start greptweet
|
||||||
|
|
||||||
Last 4 tweets:
|
Backing it up:
|
||||||
|
|
||||||
curl --compressed -s http://greptweet.com/u/webconverger/tweets.txt | head
|
docker cp greptweet:/srv/http/u/ /tmp/backup
|
||||||
|
|
||||||
# Getting a Bearer Token
|
|
||||||
|
|
||||||
When you clone and attempt to run this opensource project you will notice that
|
|
||||||
you are missing a `secret.php` file, this file contains one setting
|
|
||||||
`$bearer_token`. To [create a bearer
|
|
||||||
token](https://dev.twitter.com/docs/auth/application-only-auth):
|
|
||||||
|
|
||||||
1. [Create a new Twitter app](https://dev.twitter.com/apps/new)
|
|
||||||
1. Under OAuth settings, make a note of the **Consumer key** and **Consumer secret**
|
|
||||||
1. Now retrieve the bearer token by building a request with curl:
|
|
||||||
|
|
||||||
|
|
||||||
curl -X POST --verbose "https://api.twitter.com/oauth2/token" -d "grant_type=client_credentials" -u consumerKey:consumerSecret
|
|
||||||
|
|
||||||
The response should end like:
|
|
||||||
|
|
||||||
{"access_token":"SECRETEXAMPLESTRING","token_type":"bearer"}
|
|
||||||
|
|
||||||
Save that SECRETEXAMPLESTRING to www/secret.php:
|
|
||||||
|
|
||||||
<?php
|
|
||||||
$bearer_token = 'SECRETEXAMPLESTRING';
|
|
||||||
?>
|
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
if (empty($argv[1])) { exit(1); }
|
if (empty($argv[1])) { exit(1); }
|
||||||
$urlargs = $argv[1];
|
$urlargs = $argv[1];
|
||||||
|
|
||||||
function fetch($bearer_token, $query){
|
function fetch($query){
|
||||||
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json?";
|
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json?";
|
||||||
$headers = array(
|
$headers = array(
|
||||||
"GET /1.1/statuses/user_timeline.json?".$query." HTTP/1.1",
|
"GET /1.1/statuses/user_timeline.json?".$query." HTTP/1.1",
|
||||||
"Host: api.twitter.com",
|
"Host: api.twitter.com",
|
||||||
"Authorization: Bearer ".$bearer_token."",
|
"Authorization: Bearer ".getenv('access_token')."",
|
||||||
);
|
);
|
||||||
$ch = curl_init(); // setup a curl
|
$ch = curl_init(); // setup a curl
|
||||||
curl_setopt($ch, CURLOPT_URL, $url.$query); // set url to send to
|
curl_setopt($ch, CURLOPT_URL, $url.$query); // set url to send to
|
||||||
@@ -29,8 +29,5 @@ function fetch($bearer_token, $query){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// $bearer_token = get_bearer_token(); // bearer token seems to last
|
print fetch($urlargs); // search for the work 'test'
|
||||||
require("secret.php"); // contains $bearer_token
|
|
||||||
print fetch($bearer_token, $urlargs); // search for the work 'test'
|
|
||||||
//invalidate_bearer_token($bearer_token); // invalidate the token
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user