-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_day_list.py
85 lines (65 loc) · 1.85 KB
/
test_day_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pymysql
from datetime import datetime
#반환값 없음.
def push(keyword):
conn = pymysql.connect(
host="13.209.43.217",
user = "soyeon",
passwd = "1q2w3e4r",
db = "ajou",
charset = "utf8",
use_unicode=True
)
cur = conn.cursor()
#중복 되면 카운트 올리고 중복 아닌 키워드는 삽입하고 카운트 올림
sql = "INSERT INTO ajou.day_keyword_list(keyword) VALUES ('"+keyword+"')" + 'on duplicate key update num = num + 1'
cur.execute(sql)
#검색 한번 될때마다 튜플 정리
sql = 'select * from day_keyword_list order by num desc'
cur.execute(sql)
result = cur.fetchall()
for row in result :
print(row)
conn.commit()
conn.close()
push('학사일정')
def pull():
conn = pymysql.connect(
host="13.209.43.217",
user = "soyeon",
passwd = "1q2w3e4r",
db = "ajou",
charset = "utf8",
use_unicode=True
)
cur = conn.cursor()
#상위 10개 키워드 가져옴.
sql = 'select keyword from day_keyword_list limit 10'
cur.execute(sql)
total = cur.fetchall()
conn.close()
result = '**오늘의 인기 검색어!** \n\n'
num = 1
for row in range(0,len(total)):
result += str(num) + ' ☞ ' + total[row][0] + '\n'
num +=1
return result
def init() :
conn = pymysql.connect(
host="13.209.43.217",
user = "soyeon",
passwd = "1q2w3e4r",
db = "ajou",
charset = "utf8",
use_unicode=True
)
nowHour = datetime.today().hour
cur = conn.cursor()
if nowHour == 0 :
sql = 'SET SQL_SAFE_UPDATES =0'
cur.execute(sql)
sql = 'UPDATE day_keyword_list SET num = default'
cur.execute(sql)
conn.commit()
conn.close()
init()