Example #1
0
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
Example #2
0
def _schema():
    """returns whoosh schema for yawt articles"""
    fields = {}
    fields.update(cfg('YAWT_INDEXER_WHOOSH_INFO_FIELDS'))
    fields.update(cfg('YAWT_INDEXER_WHOOSH_FIELDS'))
    fields['article_info_json'] = STORED()
    fields['fullname'] = ID()  # add (or override) whatever is in config
    return fields
Example #3
0
def _field_values(article):
    values = {}
    _set_values(article, cfg('YAWT_INDEXER_WHOOSH_FIELDS'), values)
    _set_values(article.info, cfg('YAWT_INDEXER_WHOOSH_INFO_FIELDS'), values)
    article.info.indexed = True
    values['fullname'] = article.info.fullname
    values['article_info_json'] = jsonpickle.encode(article.info)
    return values
Example #4
0
 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 {}
Example #5
0
def notify_new_files(changed):
    """Sends out a notification about new blog files to social networks"""

    if cfg('YAWT_NOTIFY_HOSTS') and \
       socket.gethostname() not in cfg('YAWT_NOTIFY_HOSTS'):
        return

    cat_paths = []
    for cat in cfg('YAWT_NOTIFY_CATEGORIES'):
        cat_paths.append(os.path.join(content_folder(), cat))

    for added in changed.content_changes().added:
        for cpath in cat_paths:
            if added.startswith(cpath):
                _post_notification(added)
Example #6
0
def post_twitter(post):
    """Post a message to twitter"""
    api = _get_twitter_api()
    status = api.update_status(status=post)
    posturl = cfg('YAWT_MICROPOST_TWITTER_POST_URL')
    metadata = {}
    metadata['twitterpost'] = posturl.format(status.id)
    return metadata
Example #7
0
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)
Example #8
0
def _post_and_save(post, networks, link):
    metadata = post_social(post, networks, link)
    now = datetime.datetime.utcnow()
    metadata.update({'create_time': now.isoformat(),
                     'modified_time': now.isoformat()})

    tags = _extract_tags(post)
    if tags:
        metadata['tags'] = ','.join(tags)

    root_dir = g.site.root_dir
    repo_category = os.path.join(content_folder(),
                                 cfg('YAWT_MICROPOST_CATEGORY'))
    ensure_path(os.path.join(root_dir, repo_category))

    slug = "{0:02d}{1:02d}{2:02d}{3:02d}{4:02d}{5:02d}"
    slug = slug.format(now.year, now.month, now.day, now.hour, now.minute, now.second)
    repo_file = os.path.join(repo_category, slug)
    repo_file += "." + cfg('YAWT_MICROPOST_EXTENSION')
    write_post(metadata, post, os.path.join(root_dir, repo_file))
    return repo_file
Example #9
0
 def __init__(self, root=""):
     super(TagProcessor, self).__init__(root, "", cfg("YAWT_TAGGING_COUNT_FILE"))
Example #10
0
 def __init__(self, root=''):
     super(CategoryProcessor, self).__init__(root, '',
                                             cfg('YAWT_CATEGORY_COUNT_FILE'))
Example #11
0
def _idx_root():
    return cfg('WHOOSH_INDEX_ROOT')
Example #12
0
def _notify_message(file_added):
    base_url = cfg('YAWT_NOTIFY_BASE_URL')
    name = fullname(file_added)
    link = os.path.join(base_url, name)
    return (link, link)
Example #13
0
def _post_notification(added):
    (msg, link) = _notify_message(added)
    post_social(msg, cfg('YAWT_NOTIFY_NETWORKS'), link)
Example #14
0
File: vc.py Project: drivet/yawt
def _run_vc_func(funcname, *args, **kwargs):
    temp = __import__(cfg('YAWT_VERSION_CONTROL_IFC'),
                      globals(), locals(), [funcname])
    return getattr(temp, funcname)(*args, **kwargs)
Example #15
0
 def __init__(self, root=''):
     super(ArchiveProcessor, self).__init__(root, '',
                                            cfg('YAWT_ARCHIVE_COUNT_FILE'))
Example #16
0
 def _roots(self):
     return cfg(self.roots_cfg) or ['']
Example #17
0
def _canonical(info):
    return os.path.join(cfg('YAWT_BASE_URL'), info.fullname)
Example #18
0
def _run_indexer_func(funcname, *args, **kwargs):
    temp = __import__(cfg('YAWT_INDEXER_IFC'),
                      globals(), locals(), [funcname])
    return getattr(temp, funcname)(*args, **kwargs)