from trading_trend a, stock_info s \ where a.date between '" + prevday + "' and '" + currday + "' and s.code = a.code and s.market = 'KOSDAQ' \ and s.code in (select code from daily_info where date = '" + yesterday + "' and marcap between 1000000 and 10000000) \ group by a.code) A \ order by pension_fund desc, foreigner desc \ limit 5)" cur.execute(query) df = pd.read_sql(query, conn) print(df) if conn: conn.close() ret = "no|market|code|name|wics|personal|foreigner|pension_fund\n" idx = 1 for d in df.iterrows(): ret = ret + str(idx) + "|" + str(d[1]['market']) + "|" + str( d[1]['code']) + "|" + str(d[1]['name']) + "|" + str( d[1]['wics']) + "|" + str(d[1]['personal']) + "|" + str( d[1]['foreigner']) + "|" + str(d[1]['pension_fund']) + "\n" if idx % 5 == 0: ret = ret + "\n" idx = idx + 1 # print("%2d|%s|%s|%s|%f|%f" % (d[1]['s_order'], str(d[1]['code']), str(d[1]['name']), str(d[1]['sector']), d[1]['per'], d[1]['roa'])) print(ret) bot = favisbot() bot.whisper('plain', "day_top5_bysellbuy(%s-%s) \n %s" % (prevday, currday, ret))
#!/usr/bin/python import requests import time import bs4 # beautifulsoup # user define package import import sys sys.path.append("/app/favis") from msgbot.favisbot import favisbot bot = favisbot() '''@param gmtstr''' def gmtstr_to_kststr(gmtstr, gmtstr_format, kststr_format): # convert kst (gmt + 9 hour) dt = time.mktime(time.strptime(gmtstr, gmtstr_format)) + (60 * 60 * 9) return time.strftime(kststr_format,time.localtime(dt)) # DART realtime official notice rss feed url url = 'http://dart.fss.or.kr/api/todayRSS.xml' data = requests.get(url) data = bs4.BeautifulSoup(data.text, 'lxml') # extract item list notices = data.findAll("item") for notice in notices: title = notice.find('title').string link = notice.find('guid').string regdate = gmtstr_to_kststr(notice.find('dc:date').string, '%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%d %H:%M:%S')