/
quickGenerator.py
executable file
·65 lines (54 loc) · 1.67 KB
/
quickGenerator.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
exec_path = os.path.abspath(os.path.dirname(__file__)).rsplit("/",1)[0]
conf_path = exec_path+"/common/config.json"
import sys
sys.path.insert(0,exec_path)
from common import auth_api, model
from common import readReplyTable
import reply
# 解析結果に基づいて文章生成(または行動を起こす)
#import model
#import scheduler
import datetime
#from sqlalchemy import and_
import random
import string
import sys
import simplejson
def quickGenerate():
#sched = scheduler.Scheduler()
#sched.schedule()
u = LoadUserData(conf_path)
table, footer= readReplyTable.read(exec_path+"/common/replyTable.json")
dbSession = model.startSession(u)
if False:
if( sched.has_schedule() ):
str = doSchedule(sched)
else:
rep = dbSession.query(model.RetQueue)
if( rep.count() > 0 ):
str, reply_id = reply.do(table, rep,dbSession)
sendMessage(str,reply_id)
def LoadUserData(fileName):
#ファイルを開いて、データを読み込んで変換する
#データ形式は(user,password)
try:
file = open(fileName,'r')
a = simplejson.loads(file.read())
file.close()
except IOError:
print "IOError"
sys.exit(1)
return a
# Twitterにメッセージ投げる
def sendMessage(str, reply_id):
userdata = LoadUserData(conf_path)
tw = auth_api.connect(userdata["consumer_token"],
userdata["consumer_secret"], exec_path+"/common/")
str = string.replace(str,'yystart','')
str = string.replace(str,'yyend','')
tw.update_status(str, reply_id)
if __name__ == "__main__":
quickGenerate()