Compare commits
5 commits
master
...
noMastodon
Author | SHA1 | Date | |
---|---|---|---|
|
1e5c9b5554 | ||
|
141fbaf9c4 | ||
|
3fb00c7a8a | ||
|
3ce1fd3603 | ||
bebb4947fc |
5 changed files with 56 additions and 32 deletions
12
README.md
12
README.md
|
@ -15,9 +15,9 @@ First, copy `env.example` to `env`, then enter your actual login information. To
|
|||
execute the following commands:
|
||||
|
||||
```bash
|
||||
cd communistquotes
|
||||
sudo docker run -it --rm --name communistquotes --env-file env communistquotes
|
||||
sudo docker run -it --rm --name communistquotes --env-file ../env communistquotes
|
||||
cd communistquotes/templates/
|
||||
sudo docker build . -t communistquotes
|
||||
sudo docker run -it --rm --name communistquotes --env-file ../env communistquotes --debug
|
||||
```
|
||||
|
||||
## Deploy
|
||||
|
@ -26,3 +26,9 @@ Copy `inventory.example` to `inventory`, and enter your server's ssh address. Th
|
|||
```
|
||||
ansible-playbook ansible.yml --become
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
Custom flags can be used when running `main.py`:
|
||||
|
||||
* `--debug`: Dont actually login or post to the remote API
|
11
ansible.yml
11
ansible.yml
|
@ -17,13 +17,10 @@
|
|||
- name: create folder for build files
|
||||
file: path=/tmp/communistquotes state=directory
|
||||
|
||||
- name: copy build files
|
||||
copy: src=templates/{{item.filename}} dest=/tmp/communistquotes/{{item.filename}}
|
||||
with_items:
|
||||
- { filename: 'Dockerfile' }
|
||||
- { filename: 'main.py' }
|
||||
- { filename: 'marxistquotes.csv' }
|
||||
- { filename: 'requirements.txt' }
|
||||
# NOTE: It doesnt really make sense to call the folder "templates", when we actually dont use a
|
||||
# template task...
|
||||
- name: copy all build files recursively
|
||||
copy: src=templates/ dest=/tmp/communistquotes
|
||||
|
||||
- name: Build image using cache source
|
||||
docker_image:
|
||||
|
|
|
@ -7,4 +7,4 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|||
|
||||
COPY . .
|
||||
|
||||
CMD [ "python", "./main.py" ]
|
||||
ENTRYPOINT [ "python", "./main.py" ]
|
||||
|
|
|
@ -1,16 +1,24 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
from mastodon import Mastodon
|
||||
import csv
|
||||
import itertools
|
||||
import random
|
||||
import os
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='Parse quotes from .csv files, and post a random quote to Mastodon API')
|
||||
parser.add_argument('--debug', action='store_true', help='Dont actually login or post to the remote API')
|
||||
args = parser.parse_args()
|
||||
|
||||
instance = ""
|
||||
username = ""
|
||||
mastodon_api = None
|
||||
if not args.debug:
|
||||
from mastodon import Mastodon
|
||||
|
||||
instance = os.environ['MASTODON_INSTANCE']
|
||||
username = os.environ['MASTODON_USERNAME']
|
||||
|
||||
mastodon_api = None
|
||||
# Create application if it does not exist
|
||||
# TODO: store this file in volume
|
||||
if not os.path.isfile(instance+'.secret'):
|
||||
|
@ -35,9 +43,22 @@ if not os.path.isfile(instance+'.secret'):
|
|||
to_file=username+".secret"
|
||||
)
|
||||
|
||||
with open('marxistquotes.csv') as csvfile:
|
||||
quotes = []
|
||||
for root, dirs, files in os.walk('quotes/'):
|
||||
for name in files:
|
||||
(base, ext) = os.path.splitext(name)
|
||||
if ext == '.csv':
|
||||
full_name = os.path.join(root, name)
|
||||
with open(full_name) as csvfile:
|
||||
csvreader = csv.reader(csvfile, delimiter=',', quotechar='`', skipinitialspace=True)
|
||||
row = random.choice(list(csvreader))
|
||||
quotes += list(csvreader)
|
||||
|
||||
print('Found %d total quotes' % len(quotes))
|
||||
|
||||
row = random.choice(quotes)
|
||||
|
||||
text = '<p>{}</p> - {}, <a href={}>{}</a>'.format(row[0], row[1], row[2], row[3])
|
||||
toot = mastodon_api.status_post(text, visibility='public', content_type='text/html')
|
||||
print(text)
|
||||
|
||||
if not args.debug:
|
||||
mastodon_api.status_post(text, visibility='public', content_type='text/html')
|
||||
|
|
Loading…
Reference in a new issue