Skip to content

Commit

Permalink
version 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Haze committed May 9, 2017
0 parents commit 92d93b9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# shitpost.py

example: `shitpost i could kill for some sushi right about now...`

to install use PyInstaller
* pip3 install Nuitka
* nuitka --show-progress --lto --output-dir=build src/shitpost.py
5 changes: 5 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
pip3 install Nuitka
nuitka --show-progress --lto --remove-output src/shitpost.py
sudo mv shitpost.exe /usr/local/bin/shitpost
echo 'done'
36 changes: 36 additions & 0 deletions src/shitpost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
from random import randint
import requests

DANGO_ENPOINT = 'https://emoji.getdango.com/api/emoji'

def get_relevant_emojis(x):
r = requests.get(DANGO_ENPOINT, params={'q':x})
return r.json()['results']

def emojify(x):
relevant = get_relevant_emojis(x)
if relevant[0]['score'] < 0.012:
return x
if x.endswith('.'):
return x[:len(x)-1] + " " + ' '.join(list(map(lambda x: x['text'], get_relevant_emojis(x)[:randint(1, 3)]))) + '. '
else:
return x + " " + ' '.join(list(map(lambda x: x['text'], get_relevant_emojis(x)[:randint(1, 3)]))) + ' '

def split_by_random(base, char, a, e):
buff = []
b = base.split(char)
while not len(b) == 0:
to = randint(a, e)
section = b[0:to]
buff.append(' '.join(section))
b = b[to:]
return buff

base = ' '.join(sys.argv[1:])
if not base:
print('no input found.')
exit(1)

split_base = split_by_random(base, ' ', 1, 3)
print(' '.join(list(map(emojify, split_base))))

0 comments on commit 92d93b9

Please sign in to comment.