Example #1
0
def save(data, override=True):
    if override:
        orm.query(r'delete from `illegal_result`', **db_local)
    wb = Workbook()
    ws = wb.active
    ws.append(['违禁词', '次数统计', '地址', '站点名', '域名', '文章标题', '栏目'])
    sql = r"insert into `illegal_result` (`keys`,title,postid,parent_id,class_name,t_table,created_at,sitename,domain,en_project,siteid,url) values "
    for site in data:
        for i in site:
            sql += '('
            for v in i.values():
                sql += "'" + str(v) + "',"
            sql = sql.strip(',')
            sql += '),'

            ws.append([
                i['keys'],
                len(i['keys'].split(',')),
                i['url'],
                i['sitename'],
                i['domain'],
                i['title'],
                i['class_name'],
            ])
    sql = sql.strip(',')
    wb.save('asset/' + 'result' + time.strftime("%Y-%m-%d", time.localtime()) +
            '.xlsx')
    orm.query(sql, **db_local)
Example #2
0
def addWords(file='asset/illegal_words.txt', override=True):
    if override:
        orm.query(r'delete from `illegal_words`', **db_local)
    with open(file, 'r', encoding='UTF-8') as f:
        line = f.readline().strip()
        illegal_words = line.split(',')
    for v in illegal_words:
        rs = orm.query(
            r'insert into `illegal_words` (word) values ("' + v + '")',
            **db_local)
    return rs
Example #3
0
def regExpress():
    rs = orm.query(r'select word from illegal_words', **db_local)
    reg = r''
    for w in rs:
        reg += (w['word'] + r'|') if w['word'] != r'*' else ('\\' + w['word'] +
                                                             r'|')
    reg = reg.strip('|')
    logging.info('re:' + reg)
    return re.compile(reg, re.U)
Example #4
0
def query():
    tagids = request.form.getlist('tags')
    content = request.form.get('content')
    print("tagids:{}".format(tagids))
    print("content:{}".format(content))
    try:
        querylist = orm.query(tagids, content)
    except Exception as e:
        getTraceLog(e)
        return jsonify({"res": False, "msg": "Query Content and Tag Error!"})
    return jsonify({
        "res": querylist,
        "msg": "Successfully Query Entries!"
    })
Example #5
0
File: app.py Project: CCLab/cuckoo
def list_events(sid):
  import orm
  events = orm.query('case_events', sid, connection=psql.connect(conn_string))
  
  return template("events", dict(events=events))
Example #6
0
def fetchSites():
    sites = orm.query(r'select * from site order by id desc limit 50',
                      **db_local)
    return sites
Example #7
0
''' % sys.argv[0]

  sys.exit(0)
  
if __name__ == '__main__':

  try: 
    if len(sys.argv) > 1:
      args, params = getopts(sys.argv[1:], 'hlao:', ('help', 'all', 'list', 'output='))

      for opt, param in args:
        o = opt.strip('-')
        if o in ('a', 'all'):
          pass # all cases are already in cases
        elif o in ('l', 'list'):
          for c in orm.query('cases',db=DB):
            print '%s: %s' % ( c[0], c[1][0] ) 
          sys.exit(0)
        elif o in ('o', 'output'): 
          OUTFILE = codecs.open(param, mode='w', encoding='utf-8')          
        elif o in ('h', 'help'):
          help()
          
      if params:
        cases = orm.query('case_id', str(int(params[0])), db=DB)
      else:
        cases = orm.query('cases',db=DB)
        
  except getopt.GetoptError:
    help()