import pymysql
c=pymysql.connect(host="10.0.0.11",port=3306,user="java_osc",password="56Wp96Z6bS3kBpBf",database="oscdb",connect_timeout=4,read_timeout=20,write_timeout=20,charset="utf8mb4")
cur=c.cursor()
def q(sql,label):
    try:
        cur.execute(sql); rows=cur.fetchall(); cols=[d[0] for d in cur.description]
        print("=====",label,"ROWS",len(rows),"COLS",cols)
        for r in rows[:50]: print(" R",str(r)[:500])
    except Exception as e: print("=====",label,"ERR",str(e)[:200])
q("SELECT id,name,email,ident,reg_time,last_login_ip FROM osc_users WHERE name LIKE '%flag%' OR ident LIKE '%flag%' OR name LIKE '%ctf%' OR ident LIKE '%ctf%' OR email LIKE '%ctf%' LIMIT 50","users_flag")
q("SELECT id,name,email,ident,reg_time FROM osc_users ORDER BY id DESC LIMIT 20","users_recent")
q("SELECT id,title,author,create_time FROM osc_articles ORDER BY id DESC LIMIT 15","articles_recent")
q("SELECT id,title,author,create_time FROM osc_blogs ORDER BY id DESC LIMIT 15","blogs_recent")
q("SELECT id,title,create_time FROM osc_articles WHERE title LIKE '%flag%' OR title LIKE '%ctf%' OR title LIKE '%OSCTF%' LIMIT 30","articles_flag_title")
q("SELECT id,title,create_time FROM osc_blogs WHERE title LIKE '%flag%' OR title LIKE '%ctf%' OR title LIKE '%OSCTF%' LIMIT 30","blogs_flag_title")
q("SELECT id,title,create_time FROM osc_news WHERE title LIKE '%flag%' OR title LIKE '%ctf%' LIMIT 20","news_flag_title")
c.close()
