当前位置: 首页>>代码示例>>Python>>正文


Python Utils.parse_bqid方法代码示例

本文整理汇总了Python中utils.Utils.parse_bqid方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.parse_bqid方法的具体用法?Python Utils.parse_bqid怎么用?Python Utils.parse_bqid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.Utils的用法示例。


在下文中一共展示了Utils.parse_bqid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import parse_bqid [as 别名]
 def get(self):
     
     table = self.request.get("table", None)
     
     response = rules.get_rules(**GNIP_RULES_PARAMS)
     
     FORMAT = "%Y%m%d%H%M"
     end = datetime.now()
     
     # scope by table
     if table:
         
         (project, dataset, table) = Utils.parse_bqid(table)
         tag = Utils.make_tag(dataset, table)
         response = [r for r in response if r['tag'] == tag]
         
         table = Utils.get_bq().tables().get(projectId=project, datasetId=dataset, tableId=table).execute()
         
         end = float(table['creationTime'])
         end = Utils.millis_to_date(end)
         
     start = end - timedelta(days=SEARCH_DAYS)
                     
     for r in response:
         tag = r['tag']
         r['hpt'] = json.dumps({
         "publisher": "twitter", 
         "streamType": "track", 
         "dataFormat": "activity-streams", 
         "fromDate": start.strftime(FORMAT), 
         "toDate": end.strftime(FORMAT),
         "rules": [{"tag": tag, "value": r['value']}], "title": tag})
         
     self.response.headers['Content-Type'] = 'application/json'   
     self.response.out.write(json.dumps(response))
开发者ID:HectorPerez,项目名称:twitter-for-bigquery,代码行数:37,代码来源:app.py

示例2: post

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import parse_bqid [as 别名]
    def post(self):
        
        rule = self.request.get("rule", None)
        table_fqdn = self.request.get("table", None)
        (dataset, table) = Utils.parse_bqid(table_fqdn)  
        tag = Utils.make_tag(dataset, table)

        page_next = self.request.get("page_next", None)
        page_count = self.request.get("page_count", None)
        count_total = int(self.request.get("count_total", 0))
        if not page_count:
            page_count = 0
        else:
            page_count = int(page_count) + 1

        end = datetime.now()
        start = end - timedelta(days=SEARCH_DAYS)
        
        # for logging purposes, show the estimate 
        if not page_next:
        
            # Initial count
            g = Utils.get_gnip()
            timeline = g.query(rule, 0, record_callback=None, use_case="timeline", start=start, end=end, count_bucket="day")
            timeline = json.loads(timeline)
            
            count_estimate = 0 
            for r in timeline["results"]:
                count_estimate = count_estimate + r["count"]
                
            logging.info("Task start: %s => %s (est. %s)" % (rule, tag, count_estimate))
            
        g = Utils.get_gnip()
        tweets = g.query(rule, use_case="tweets", start=start, end=end, page=page_next)

        try: 
             
            timing_start = datetime.now()
            response = Utils.insert_records(dataset, table, tweets)
            timing = datetime.now() - timing_start

            count_total = count_total + len(tweets)
         
            logging.info("Task page %s: %s => %s (%s, %sms)" % (page_count, rule, tag, count_total, timing))
            
        except:
 
            logging.exception("Unexpected error:");

        page_next = g.rule_payload.get("next", None)
        if page_next:
            self.enqueue(rule, table_fqdn, page_next, page_count=page_count, count_total=count_total)

        response = {
            "completed" : True
        }
        self.response.headers['Content-Type'] = 'application/json'   
        self.response.out.write(json.dumps(response))
开发者ID:jmg132,项目名称:twitter-for-bigquery,代码行数:60,代码来源:app.py

示例3: get

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import parse_bqid [as 别名]
 def get(self, id):
     
     (project, dataset, table) = Utils.parse_bqid(id)
     response = Utils.get_bq().tables().get(projectId=project, datasetId=dataset, tableId=table).execute()
     
     created = float(response['creationTime'])
     response['creationTime'] = Utils.millis_to_str(created)
     
     updated = float(response['lastModifiedTime'])
     response['lastModifiedTime'] = Utils.millis_to_str(updated)
     
     self.response.out.write(JINJA.get_template('table_detail.html').render(response))
开发者ID:jmg132,项目名称:twitter-for-bigquery,代码行数:14,代码来源:app.py


注:本文中的utils.Utils.parse_bqid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。