# db_conn = config.mongo_conn().explorer
redis_conn = config.redis_conn()

str_date = datetime.datetime.now().strftime('%Y%m%d')
logger = config.logger
_file = logger['mempool']['path'] + 'rajchain_latest_transactions_%s' % str_date
logging.basicConfig(
    filename=_file,
    filemode='a',
    format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
    datefmt='%H:%M:%S',
    level=logging.DEBUG)
_logging = logging.getLogger('explorer')
_logging.addHandler(logging.StreamHandler(sys.stdout))
mongo_conn = config.mongo_conn()
db_conn = mongo_conn.rajchain_explorer


def insert_transactions_in_redis():
    start_time = int(time.time())
    logging.info('script started at::: %s' % start_time)
    print redis_conn.exists('raj_key')
    if redis_conn.exists('raj_key') is not True:
        redis_conn.set('raj_key', True)
        # redis_conn.set('rajchain_assets_count',len(custom_rpc('listassets')))
        # print 'tyty %s' %custom_rpc('liststreams')
        # redis_conn.set('rajchain_streams_count',len(custom_rpc('liststreams')))
        run_flag = True
        while run_flag is True:
            end_time = int(time.time())
Пример #2
0
 def save_to_mongo(entity):
     db = mongo_conn()
     entity['collection'] = time_strftime()
     db['daily_collection'].insert(entity)
__author__ = 'udasi'

import config
from models import *
from wrap_core import *

db_conn = config.mongo_conn().explorer
redis_conn = config.redis_conn()

crawled_block_height = int(redis_conn.get('current_block_height'))
current_block_height = getblockcount(config.testnet['btc_prefix'],
                                     config.payload)


def crawl_new_blocks():
    if crawled_block_height == current_block_height:
        print 'no new blocks'
        pass
    else:
        #   ----------- update previous blocks next_block_hash ------------
        latest_nextblock_height = latest_nextblock_height_model()
        for i in range(latest_nextblock_height, crawled_block_height + 1):
            block_hash = getblockhash(config.testnet['btc_prefix'],
                                      config.payload, i)
            block_info = getblock(config.testnet['btc_prefix'], config.payload,
                                  block_hash)
            if 'nextblockhash' in block_info:
                response = update_nextblockhash(i, block_info['nextblockhash'])
                print '====== nextblockhash update response ======== %s' % response
            else:
                pass
Пример #4
0
 def get_account():
     # 老版
     # url = 'http://124.239.144.181:7114/Schedule/dispatch?type=8'
     # # url = 'http://183.131.241.60:38011/nextaccount?label=5'
     # resp = requests.get(url, timeout=30)
     # # data 可能为空
     # data_json = resp.text.get('data')
     # data = json.loads(data_json)
     # self.search_name = data.get('name')
     # print(self.search_name)
     # return self.search_name
     # 重点采集接口
     # account_all = []
     # try:
     #     url = 'http://183.131.241.60:38011/nextaccount?label=5'
     #     resp = requests.get(url, timeout=21)
     #     items = json.loads(resp.text)
     #     if len(items) == 0:
     #         return []
     #     for item in items:
     #         account_all.append(item.get('account'))
     #     log.info("开始account列表 {}".format(account_all))
     # except Exception as e:
     #     log.info('获取账号列表错误 {}'.format(e))
     #     time.sleep(5)
     # 统计账号
     collection_name = 'run_counts'
     try:
         url = 'http://dispatch.yunrunyuqing.com:38082/ScheduleDispatch/dispatch?type=8'
         resp = requests.get(url, timeout=30)
         data = json.loads(resp.text).get('data')
         if not data:
             # 即返回None
             return
         account = json.loads(data).get('account')
         db = mongo_conn()
         result = db[collection_name].find({})
         if result.count() == 0:
             db[collection_name].insert({
                 'account_count': 1,
                 'article_count': 0,
                 'start': time_strftime(),
                 'end': None,
                 'save_name': save_name()
             })
             log.info("插入mongo成功")
         else:
             updated = False
             for item in db[collection_name].find():
                 if item.get('save_name') == save_name():
                     count = item.get(
                         'account_count'
                     ) + 1  # if item.get('account_count') else 0
                     log.info(item)
                     db[collection_name].update(
                         {'save_name': save_name()}, {
                             '$set': {
                                 'account_count': count,
                                 'end': time_strftime()
                             }
                         },
                         upsert=True)
                     updated = True
                     log.info("更新mongo成功")
                     break
             if updated is False:
                 log.info('找不到save_name,需要插入')
                 db[collection_name].insert({
                     'account_count': 1,
                     'article_count': 0,
                     'start': time_strftime(),
                     'end': None,
                     'save_name': save_name()
                 })
                 log.info("插入mongo成功")
     except Exception as e:
         log.info('调度获取account出错:{}'.format(e))
         return None
     return [account]
__author__ = 'udasi'
import config
from wrap_core import *
import time
import logging
import datetime
import sys

db_conn = config.mongo_conn().rajchain_explorer
redis_conn = config.redis_conn()

str_date = datetime.datetime.now().strftime('%Y%m%d')
logger = config.logger
_file = logger['mempool']['path'] + 'multichain_addressv4_%s' % str_date
logging.basicConfig(
    filename=_file,
    filemode='a',
    format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
    datefmt='%H:%M:%S',
    level=logging.DEBUG)
_logging = logging.getLogger('explorer')
_logging.addHandler(logging.StreamHandler(sys.stdout))


class exec_time():
    def __init__(self):
        self.start_epoch = time.time()

    def get_duration(self):
        self.end_epoch = time.time()
        duration = self.end_epoch - self.start_epoch