Ejemplo n.º 1
0
 def task2(self, s_url, begin, end):
     logger = Logger()
     path = '//div[@class="bd"]/ul/li[@class="position_shares"]/div/'
     driver = webdriver.Chrome()
     for url in s_url[begin:end]:
         logger.info(url)
         driver.get(url)
         temp = random.randint(9, 20)
         time.sleep(temp)
         list_fund_code = [url[26:32] for i in xrange(10)]
         try:
             list_stock_name = self.get_text(
                 driver.find_elements_by_xpath(
                     path + 'table/tbody/tr/td[1]')[0:10])
             list_stock_per = self.get_text(
                 driver.find_elements_by_xpath(
                     path + 'table/tbody/tr/td[2]')[0:10])
             sum = self.get_text(
                 driver.find_elements_by_xpath(path + 'p/span[2]'))
             list_per_sum = [sum[0] for i in xrange(10)]
         except Exception as e:
             logger.error(e)
             continue
         dict_df = {
             u'基金代码': pd.Series(list_fund_code),
             u'股票名称': pd.Series(list_stock_name),
             u'股票占比': pd.Series(list_stock_per),
             u'前十持仓占比合计': pd.Series(list_per_sum)
         }
         df = pd.DataFrame(dict_df,
                           columns=[u'基金代码', u'股票名称', u'股票占比', u'前十持仓占比合计'])
         print(df)
         # df.to_excel('./Data3/fund_position_' + str(url[26:32]) + '.xlsx', index=False)
     driver.close()
     pass
Ejemplo n.º 2
0
class Base:
    def __init__(self, master):
        self.name = None   # "name"
        self.commands = []   # ["\command", ...]
        self.master = master
        self.LOG = Logger('./log', 'plugins')
        return

    def initialize(self):
        return

    def __call__(self, cmd: str, arg: Optional[str] = None) -> bool:

        return False

    def on_stop(self):
        return

    def log_info(self, msg):
        self.LOG.info("[%s]: %s" % (self.name, msg))
        return

    def log_warn(self, msg):
        self.LOG.warn("[%s]: %s" % (self.name, msg))
        return

    def log_error(self, msg):
        self.LOG.error("[%s]: %s" % (self.name, msg))
        return
Ejemplo n.º 3
0

@app.route('/api/yuming/search', methods=['GET', 'POST'])
def api_yuming_search():
    try:
        response = {}
        # get the task id that need be deleted
        name = flask.request.form.get('name', 'null')
        if name == 'null':
            logger.warning("not get param name")
            response['result'] = 'error'
        else:
            logger.debug("get param name=%s" % (name))

            # should check the name, should end of '.com' or '.net'
            info = server.search_yuming_info(name)
            response['result'] = 'success'
            response['info'] = info
        return json.dumps(response)

    except Exception, ex:
        logger.error("api_yuming_search error:%s" % (ex))
        response['result'] = 'error'
        response['message'] = '%s' % (ex)
        return json.dumps(response)


if __name__ == "__main__":
    logger.info("__main__")
    app.run('0.0.0.0', 9090, debug=True, threaded=True)
Ejemplo n.º 4
0
        return json.dumps(response)

@app.route('/api/yuming/search', methods=['GET','POST'])
def api_yuming_search():
    try:
        response = {}
        # get the task id that need be deleted
        name = flask.request.form.get('name','null')
        if name == 'null':
            logger.warning("not get param name")
            response['result'] = 'error'
        else:
            logger.debug("get param name=%s" %(name))
            
            # should check the name, should end of '.com' or '.net'
            info = server.search_yuming_info(name)
            response['result'] = 'success'
            response['info'] = info
        return json.dumps(response)

    except Exception,ex:
        logger.error("api_yuming_search error:%s" %(ex))
        response['result'] = 'error'
        response['message'] = '%s' %(ex)
        return json.dumps(response)


if __name__ == "__main__":
    logger.info("__main__")
    app.run('0.0.0.0', 9090, debug = True,  threaded = True)
Ejemplo n.º 5
0
class TagReader():
    config_filename = "config.cfg"

    def __init__(self):

        self.last_tag_scanned = 0
        self.tag_scan_count = 0
        self.tag_scan_repeat_message = 3

        self.config = ConfigParser.RawConfigParser()
        self.config.read(self.config_filename)
        self.push_apikey = self.config.get('Pushover', 'access_token')
        self.push_userkey = self.config.get('Pushover', 'user_key')
        log_filename = self.config.get('Logging', 'tag_filename')
        log_filesize = self.config.get('Logging', 'size_bytes')
        log_backup_count = self.config.get('Logging', 'backup_count')
        self.log = Logger(log_filename, log_filesize, log_backup_count,
                          self.push_apikey, self.push_userkey, "HHSAccess")
        debug_nopigpio = self.config.getboolean('Debug', 'nopigpio')

        self.dc = dc(nopigpio=debug_nopigpio)
        self.dc.set_tag_scanned_callback(self.tag_scanned)
        self.dc.set_alarm_sounding_callback(self.alarm_sounding)
        self.dc.set_alarm_armed_callback(self.alarm_armed)
        self.db = sdb("members.db")
        self.log.log_and_notify("Startup completed", "System startup")
        #member, is_allowed = self.db.is_allowed(39160494)
        #self.tag_scanned(0, 99412070)
        #print str((member, is_allowed))

    def unlock_door(self, contact_name):
        self.tag_scan_count = 0
        self.dc.unlock_door()
        self.log.new_occupant(contact_name)
        pass

    def open_door(self, contact_name):
        self.tag_scan_count = 0
        self.dc.unlock_door()
        self.log.new_occupant(contact_name)

    def tag_scanned(self, bits, rfid):
        self.log.info("Tag scanned: " + str(rfid))
        contact, is_allowed = self.db.is_allowed(rfid)
        print contact, is_allowed
        contact_name = "Unknown"
        if contact is not None:
            contact_name = str(contact[1]) + " " + str(contact[2])
            info_str = "Contact found: " + contact_name

            if is_allowed is True:
                info_str += " - allowed."
            else:
                info_str += " - not allowed."
                self.log.notify(
                    contact_name + " tried to enter but not allowed.",
                    "not allowed in")
            self.log.info(info_str)
            if is_allowed: self.open_door(contact_name)
        else:
            self.log.info("Unknown ID.")

        if not is_allowed:
            #self.log.invalid_tag_retries(rfid, contact_name)

            # Check for repeat scans
            if (rfid == self.last_tag_scanned):
                self.tag_scan_count += 1
                if (self.tag_scan_count >= self.tag_scan_repeat_message):
                    self.log.invalid_tag_retries(rfid, contact_name)
            else:
                self.tag_scan_count = 0
            self.last_tag_scanned = rfid
        pass

    def alarm_sounding(self):
        self.log.alarm_sounding()
        pass

    def alarm_armed(self):
        self.log.alarm_armed()
        pass

    def reload_db(self):
        pass

    def run(self):
        while (True):
            time.sleep(30 * 60 * 60)
            self.log.info("Heartbeat")