-
Notifications
You must be signed in to change notification settings - Fork 0
/
godsings.py
56 lines (51 loc) · 1.68 KB
/
godsings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from flask import Flask, render_template
from pytunegen.tunegen import TuneGen
import random
import time
import requests
import os
def generateMusic(seed=0):
godsaid = "I'm down"
try:
response = requests.get('https://godsays.xyz')
if response.status_code == 200:
godsaid = str(response.content, 'utf-8')
if seed == 0:
for word in godsaid.split(" "):
for char in word:
seed += ord(char)
except:
print("god is down")
tunegen = TuneGen(seed=seed, music_length=20)
music = tunegen.generate()
note_pitches = []
note_durations = []
for bar in music:
for note in bar.notes:
note_pitches.append(note.pitch)
note_durations.append(note.duration)
sensible_music = []
for i in range(len(note_pitches)):
sensible_music.append([note_pitches[i], note_durations[i] * (60/tunegen.bpm_current)])
return godsaid, sensible_music, seed
app = Flask(__name__, template_folder='templates')
app.debug = True
app._static_folder = os.path.abspath("templates/static/")
@app.route('/', methods=['GET'])
def index():
words, song, seed = generateMusic()
return render_template('layouts/index.html',
words=words,
song=song,
seed=seed)
@app.route('/<seed>', methods=['GET'])
def custom_seed(seed):
try:
seed = int(seed)
except:
pass
words, song, seed = generateMusic(seed=seed)
return render_template('layouts/index.html',
words=words,
song=song,
seed=seed)