Esempio n. 1
0
    def suspend(self, suspended_until=None, message=None):
        """
        Suspend the token until the given utc timestamp
        """
        if suspended_until:
            self.suspended_until = datetime.utcfromtimestamp(suspended_until)
        else:
            self.suspended_until = None
        self.last_message = message
        self.save()

        if suspended_until:
            # We make the `suspended_until` key auto expire
            key = self.key('suspended_until')
            connection.expire(key, round(suspended_until - now_timestamp()) + 1)
Esempio n. 2
0
File: views.py Progetto: p7k/daizy
def videos_increment(request, limit=30):
    graph = fb_sdk.GraphAPI(request.session['oauth_token'])
    sources = []
    # always return at least two to avoid
    while len(sources) < 2:
        timestamp = request.session.get('facebook_timestamp', now_timestamp())
        fql = fql_query(timestamp, limit=limit)
        # import ipdb; ipdb.set_trace()
        # TODO secure this call with some exception handling + timeout
        json_results = graph.fql(fql)
        if not json_results: break
        request.session['facebook_timestamp'] = json_results[-1]['created_time']
        video_posts = imap(skinny_video_post, json_results)
        sources += list(ifilter(None, video_posts))
    return JSONResponse(sources)
Esempio n. 3
0
def visited_links():
    try:
        json = request.json
    except Exception as e:
        return make_json_response(error=e, code=HTTPStatus.BAD_REQUEST)

    try:
        links = Links.from_json(json)
    except Exception as e:
        return make_json_response(error=e, code=HTTPStatus.BAD_REQUEST)

    try:
        redis_connector.add(links.links, now_timestamp())
    except Exception as e:
        return make_json_response(error=ERROR_INTERNAL, code=HTTPStatus.INTERNAL_SERVER_ERROR)

    return make_json_response()
Esempio n. 4
0
File: stats.py Progetto: stablum/soa
import utils

from org.gephi.statistics.plugin import GraphDistance
import gi
import config
import floyd_warshall
import main
import os

collector = None
history = []
run_num = 0
run_timestamp = utils.now_timestamp()

def infer_stats_filename():
    return config.stats_filename.replace(".csv","_"+config.policy_id+".csv")

def new_collector_dict():
    """
    returns the dict that describes the current data collection "snapshot"
    """
    ret = {
        'count_iterations':main.count_iterations,
        'num_kills':0,
        'total_weight':0,
        'path_length':0,    # http://gephi.org/docs/toolkit/org/gephi/statistics/plugin/GraphDistance.html#getPathLength()
        'run_num':run_num,
        'mean_edges_importance':0,
        'std_edges_importance':0
    }
    return ret