예제 #1
0
파일: test_tagging.py 프로젝트: drivet/yawt
    def test_counts_tagging_with_bases_on_walk(self):
        self.app.config['YAWT_TAGGING_BASE'] = ['reading', 'cooking']
        self._walk()

        readingcounts_path = os.path.join(abs_state_folder(),
                                          'reading/tagcounts')
        readingcountobj = jsonpickle.decode(load_file(readingcounts_path))

        cookingcounts_path = os.path.join(abs_state_folder(),
                                          'cooking/tagcounts')
        cookingcountobj = jsonpickle.decode(load_file(cookingcounts_path))

        self.assertEquals(2, len(readingcountobj.keys()))
        self.assertEquals(3, len(cookingcountobj.keys()))
예제 #2
0
    def test_counts_categories_with_bases_on_walk(self):
        self.app.config['YAWT_CATEGORY_BASE'] = ['reading', 'cooking']
        self._walk()

        readingcounts_path = os.path.join(abs_state_folder(),
                                          'reading/categorycounts')
        readingcountobj = jsonpickle.decode(load_file(readingcounts_path))

        cookingcounts_path = os.path.join(abs_state_folder(),
                                          'cooking/categorycounts')
        cookingcountobj = jsonpickle.decode(load_file(cookingcounts_path))

        self.assertEquals(1, readingcountobj.count)
        self.assertEquals(2, cookingcountobj.count)
예제 #3
0
파일: test_tagging.py 프로젝트: drivet/yawt
    def test_counts_tagging_with_count_file_on_walk(self):
        self.app.config['YAWT_TAGGING_COUNT_FILE'] = '_anothercountfile'
        self._walk()

        counts_path = os.path.join(abs_state_folder(), '_anothercountfile')
        countobj = jsonpickle.decode(load_file(counts_path))
        self.assertEquals(5, len(countobj.keys()))
예제 #4
0
파일: facebook.py 프로젝트: drivet/yawt
def post_fb(post, link=None):
    """Post message to facebook"""
    token_file = os.path.expanduser(cfg('YAWT_MICROPOST_FB_ACCESS_TOKEN_FILE'))
    access_tok = load_file(token_file)
    graph = facepy.GraphAPI(access_tok)

    if link:
        print("trying force facebook to scrape URL...")
        graph.post('/', id=link, scrape=True)
        print("trying to post to facebook...")
        response = graph.post('me/feed', message=post, link=link)
    else:
        response = graph.post('me/feed', message=post)
    print("response: "+str(response))
    fid = None
    retid = response['id']
    if retid:
        pids = retid.split('_')
        if len(pids) < 2:
            print("unexpected id format")
        fid = pids[1]
    posturl = cfg('YAWT_MICROPOST_FB_POST_URL')
    metadata = {}
    if fid:
        metadata['fbpost'] = posturl.format(fid)
    return metadata
예제 #5
0
파일: test_tagging.py 프로젝트: drivet/yawt
    def test_adjusts_tagging_with_bases_on_update(self):
        self.app.config['YAWT_TAGGING_BASE'] = ['reading', 'cooking']
        self._walk()

        self.site.change(added={'content/reading/emma.txt': EMMA},
                         modified={'content/cooking/indian/madras.txt': NEW_MADRAS},
                         deleted=['content/cooking/soup.txt'])

        readingcounts_path = os.path.join(abs_state_folder(),
                                          'reading/tagcounts')
        readingcountobj = jsonpickle.decode(load_file(readingcounts_path))

        cookingcounts_path = os.path.join(abs_state_folder(),
                                          'cooking/tagcounts')
        cookingcountobj = jsonpickle.decode(load_file(cookingcounts_path))

        self.assertEquals(3, len(readingcountobj.keys()))
        self.assertEquals(1, len(cookingcountobj.keys()))
예제 #6
0
    def test_adjusts_categories_with_bases_on_update(self):
        self.app.config['YAWT_CATEGORY_BASE'] = ['reading', 'cooking']
        self._walk()

        self.site.change(added={'content/reading/emma.txt':
                                'pretty funny'},
                         modified={'content/cooking/indian/madras.txt':
                                   'mild'},
                         deleted=['content/cooking/soup.txt'])

        readingcounts_path = os.path.join(abs_state_folder(),
                                          'reading/categorycounts')
        readingcountobj = jsonpickle.decode(load_file(readingcounts_path))

        cookingcounts_path = os.path.join(abs_state_folder(),
                                          'cooking/categorycounts')
        cookingcountobj = jsonpickle.decode(load_file(cookingcounts_path))

        self.assertEquals(2, readingcountobj.count)
        self.assertEquals(1, cookingcountobj.count)
예제 #7
0
파일: __init__.py 프로젝트: drivet/yawt
 def context_processor(summaryfile_cfg, bases_cfg, varname):
     """Return a single value dictionary containing the summary file which
     currently applies"""
     summary_file = cfg(summaryfile_cfg)
     bases = cfg(bases_cfg) or ['']
     for base in bases:
         if request.path.startswith('/'+base):
             path = os.path.join(abs_state_folder(), base, summary_file)
             loaded_file = load_file(path)
             return single_dict_var(varname, jsonpickle.decode(loaded_file))
     return {}
예제 #8
0
파일: twitter.py 프로젝트: drivet/yawt
def _get_twitter_api():
    credfile = cfg('YAWT_MICROPOST_TWITTER_CREDENTIALS_FILE')
    cfgfile = os.path.expanduser(credfile)
    cfgobj = yaml.load(load_file(cfgfile))
    consumer_key = cfgobj['consumer_key']
    consumer_secret = cfgobj['consumer_secret']
    access_token = cfgobj['access_token']
    access_token_secret = cfgobj['access_token_secret']
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    return tweepy.API(auth)
예제 #9
0
    def test_counts_categories_with_count_file_on_walk(self):
        self.app.config['YAWT_CATEGORY_COUNT_FILE'] = '_anothercountfile'
        self._walk()

        counts_path = os.path.join(abs_state_folder(), '_anothercountfile')
        countobj = jsonpickle.decode(load_file(counts_path))

        self.assertEquals(3, countobj.count)
        self.assertEquals(2, len(countobj.children))
        self.assertEquals(1, countobj.child('reading').count)
        self.assertEquals(2, countobj.child('cooking').count)
        self.assertEquals(1, len(countobj.child('cooking').children))
        self.assertEquals(1, countobj.child('cooking').child('indian').count)
예제 #10
0
    def test_counts_archives_with_count_file_on_walk(self):
        self.app.config['YAWT_ARCHIVE_COUNT_FILE'] = '_anothercountfile'
        self._walk()

        counts_path = os.path.join(abs_state_folder(), '_anothercountfile')
        countobj = jsonpickle.decode(load_file(counts_path))
        self.assertEquals(3, countobj.count)
        self.assertEquals(2, len(countobj.children))
        self.assertEquals(1, countobj.child('2008').count)
        self.assertEquals(2, countobj.child('2007').count)
        self.assertEquals(1, len(countobj.child('2007').children))
        self.assertEquals(2, countobj.child('2007').child('06').count)
        self.assertEquals(1, countobj.child('2007').child('06').child('01').count)
        self.assertEquals(1, countobj.child('2007').child('06').child('02').count)
        self.assertEquals(1, countobj.child('2008').child('06').child('03').count)
예제 #11
0
파일: siteutils.py 프로젝트: drivet/yawt
 def load_state_file(self, rel_filename):
     abs_state_file = os.path.join(self.state_root, rel_filename)
     return load_file(abs_state_file)
예제 #12
0
파일: siteutils.py 프로젝트: drivet/yawt
 def load_template(self, rel_filename):
     abs_template_file = os.path.join(self.abs_template_root(), rel_filename)
     return load_file(abs_template_file)
예제 #13
0
파일: siteutils.py 프로젝트: drivet/yawt
 def load_content(self, rel_filename):
     abs_content_file = os.path.join(self.abs_content_root(), rel_filename)
     return load_file(abs_content_file)
예제 #14
0
파일: __init__.py 프로젝트: drivet/yawt
 def _load_summary(self):
     self.summary = jsonpickle.decode(load_file(self._abs_summary_file()))
예제 #15
0
파일: __init__.py 프로젝트: drivet/yawt
 def load_file(self, repofile):
     return load_file(os.path.join(self.site_root, repofile))