Fixed RAM usage bug

Pushing straight to master since this is an extremely simple fix, with
a pretty large performance benefit.

The Phyme library used for generating a User Agent rhyme was consuming
an absolute unit of memory. Now that it's removed, it's using about 10x
less memory, at the cost of User Agents being not as funny anymore.
pull/33/head
Ben Busby 4 years ago
parent 6e1af0aa9e
commit 445019d204

@ -1,6 +1,6 @@
from app import rhyme
from io import BytesIO
import pycurl
import random
import urllib.parse as urlparse
# Base search url
@ -16,9 +16,9 @@ VALID_PARAMS = ['tbs', 'tbm', 'start', 'near']
def gen_user_agent(normal_ua):
is_mobile = 'Android' in normal_ua or 'iPhone' in normal_ua
mozilla = rhyme.get_rhyme('Mo') + rhyme.get_rhyme('zilla')
firefox = rhyme.get_rhyme('Fire') + rhyme.get_rhyme('fox')
linux = rhyme.get_rhyme('Lin') + 'ux'
mozilla = random.choice(['Moo', 'Woah', 'Bro', 'Slow']) + 'zilla'
firefox = random.choice(['Choir', 'Squier', 'Higher', 'Wire']) + 'fox'
linux = random.choice(['Win', 'Sin', 'Gin', 'Fin', 'Kin']) + 'ux'
if is_mobile:
return MOBILE_UA.format(mozilla, firefox)

@ -1,25 +0,0 @@
import itertools
from Phyme import Phyme
import random
import sys
import time
random.seed(time.time())
ph = Phyme()
def get_rhyme(word):
# Get all rhymes and merge to one list (normally separated by syllable count)
rhymes = ph.get_perfect_rhymes(word)
rhyme_vals = list(itertools.chain.from_iterable(list(rhymes.values())))
# Pick a random rhyme and strip out any non alpha characters
rhymed_word = rhyme_vals[random.randint(0, len(rhyme_vals) - 1)]
rhymed_word = ''.join(letter for letter in rhymed_word if letter.isalpha())
return rhymed_word.capitalize()
if __name__ == '__main__':
print(get_rhyme(sys.argv[1]))

@ -7,7 +7,6 @@ Flask==1.1.1
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
Phyme==0.0.9
pycparser==2.19
pycurl==7.43.0.4
pyOpenSSL==19.1.0

Loading…
Cancel
Save