Skip to content

Commit

Permalink
First try: config for heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
chantmk committed Jul 25, 2021
1 parent 9c6bcd1 commit 9dfc5a4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker: python bot.py
35 changes: 29 additions & 6 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,38 @@
from os import listdir
from gtts import gTTS

import requests
import re
from tqdm import tqdm

last = None

try:
with open('sentence_mapper.json', 'r') as f:
sentence_mapper = json.load(f)
except:
print('Please create sentence_mapper.json')
exit()
def create_sentence_mapper():
os.makedirs('clips', exist_ok=True)

raw_sounds = requests.get('https://prophet-button.netlify.app/')
extracted_data = re.findall(r'src=\"(.*\.mp3)\".*\">([^\"<]*)<', raw_sounds.text)

sentence_mapper = dict()
for (filename, sentence) in tqdm(extracted_data):
sentence_mapper[' '.join(sentence.split()).strip()] = filename
r = requests.get(f'https://prophet-button.netlify.app/sound/{filename}')
with open(f'clips/{filename}', 'wb') as f:
f.write(r.content)

with open('sentence_mapper.json', 'w') as f:
json.dump(sentence_mapper, f)

def get_sentence_mapper():
global sentence_mapper
try:
with open('sentence_mapper.json', 'r') as f:
sentence_mapper = json.load(f)
except FileNotFoundError:
create_sentence_mapper()
get_sentence_mapper()

get_sentence_mapper()

bot = commands.Bot(command_prefix=['clip!', 'c!', '?'])

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ discord
python-dotenv
gtts
discord.py[voice]
ffmpeg
ffmpeg
tqdm
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.9.2
23 changes: 12 additions & 11 deletions url2mp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
from tqdm import tqdm
import json

os.makedirs('clips', exist_ok=True)
def create_sentence_mapper():
os.makedirs('clips', exist_ok=True)

raw_sounds = requests.get('https://prophet-button.netlify.app/')
extracted_data = re.findall(r'src=\"(.*\.mp3)\".*\">([^\"<]*)<', raw_sounds.text)
raw_sounds = requests.get('https://prophet-button.netlify.app/')
extracted_data = re.findall(r'src=\"(.*\.mp3)\".*\">([^\"<]*)<', raw_sounds.text)

sentence_mapper = dict()
for (filename, sentence) in tqdm(extracted_data):
sentence_mapper[' '.join(sentence.split()).strip()] = filename
r = requests.get(f'https://prophet-button.netlify.app/sound/{filename}')
with open(f'clips/{filename}', 'wb') as f:
f.write(r.content)
sentence_mapper = dict()
for (filename, sentence) in tqdm(extracted_data):
sentence_mapper[' '.join(sentence.split()).strip()] = filename
r = requests.get(f'https://prophet-button.netlify.app/sound/{filename}')
with open(f'clips/{filename}', 'wb') as f:
f.write(r.content)

with open('sentence_mapper.json', 'w') as f:
json.dump(sentence_mapper, f)
with open('sentence_mapper.json', 'w') as f:
json.dump(sentence_mapper, f)

0 comments on commit 9dfc5a4

Please sign in to comment.