-
Notifications
You must be signed in to change notification settings - Fork 0
/
Creativecrocodile.py
30 lines (24 loc) · 963 Bytes
/
Creativecrocodile.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
import sublime
import sublime_plugin
import random
import json
class CreativecrocodileCommand(sublime_plugin.TextCommand):
@classmethod
def get_adjective(self):
data_file = sublime.load_resource("Packages/CreativeCrocodile/adjectives.json")
data = sublime.decode_value(data_file)
random.shuffle(data)
return data[0]
@classmethod
def get_animal(self, adjective):
data_file = sublime.load_resource("Packages/CreativeCrocodile/animals.json")
data = sublime.decode_value(data_file)
letter = adjective[:1].lower()
matchedAnimals = data[letter]
random.shuffle(matchedAnimals)
return matchedAnimals[0]
def run(self, edit):
adjective = CreativecrocodileCommand.get_adjective()
animal = CreativecrocodileCommand.get_animal(adjective)
out = adjective + " " + animal + " "
self.view.insert(edit, self.view.sel()[0].begin(), out)