-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeme_provider.py
More file actions
32 lines (23 loc) · 787 Bytes
/
meme_provider.py
File metadata and controls
32 lines (23 loc) · 787 Bytes
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
"""Meme provider"""
import random
class MemeProvider(object):
"""
It makes a list base on a tab separated file
"""
def __init__(self, text_provider):
text = text_provider.get_text()
self.list = {}
for line in text.split("\n"):
key_val = line.split(",")
if not key_val[0] in self.list.keys():
self.list[key_val[0]] = []
self.list[key_val[0]].append(key_val[1])
def get_random_meme(self, text):
"""Gets a random meme based on a text"""
matches = []
for key, value in self.list.iteritems():
if key in text:
matches = matches + value
if matches:
return matches[random.randint(0, len(matches))]
return None