コード例 #1
0
ファイル: phrase.py プロジェクト: hahayes/these-days
import json
import random

from bin.utils import lazypath
FILENAME = lazypath('static', 'words.json')

def dump(outfile=FILENAME):
    from pattern.en import wordnet, conjugate, pluralize
    from pattern.en.wordlist import BASIC
    basic_words = lambda pos, fcn=(lambda x: x): [fcn(w) for w in BASIC if wordnet.synsets(w, pos=pos)]
    lkp = {'NOUNS': basic_words('NNS', pluralize), 'VERBS': basic_words('VB', lambda x: conjugate(x, 'part')), 'ADJS': basic_words('JJ')}
    json.dump(lkp, open(outfile, 'w'))

def load(infile=FILENAME):
    return json.load(open(infile))

def phrase(lkp):
    return '{0} the {1}'.format(random.choice(lkp['VERBS']), random.choice(lkp['NOUNS']))

if __name__ == '__main__':
    dump()
コード例 #2
0
ファイル: TheseDays.py プロジェクト: hahayes/these-days
import urllib
import os.path
import subprocess
import webbrowser
from datetime import datetime

import rumps
from bin.phrase import load, phrase
from bin.utils import lazypath, data_dump, init_browser

words = load()
rumps.debug_mode(True)

ICONFILE = lazypath('static', 'icon.png')
HTMLDIR = lazypath('static')
SETTINGS_DIR = rumps.application_support('These Days')
DATAFILE = os.path.join(SETTINGS_DIR, 'data.json')
BROWSERFILE = os.path.join(SETTINGS_DIR, 'index.html')

class TheseDaysApp(rumps.App):
    def __init__(self):
        super(TheseDaysApp, self).__init__("These Days", title=None, icon=ICONFILE)
        self.menu = ["These days...", "View history", rumps.separator, "Auto-ask?", "Preferences"]
        self.browser_url = BROWSERFILE
        self.settings_dir = SETTINGS_DIR
        self.datafile = DATAFILE
        init_browser(HTMLDIR, SETTINGS_DIR)
        self.PORT = 1988

    # @rumps.clicked("Preferences")
    # def prefs(self, _):