-
Notifications
You must be signed in to change notification settings - Fork 0
/
guildach.py
41 lines (38 loc) · 1.73 KB
/
guildach.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
import os, json, requests, urllib, logging
import MySQLdb as mdb
from connection import conn,x
from apikey import key
Host = "https://us.api.battle.net"
logging.basicConfig(filename='/var/log/guildinfo.log', level=logging.WARNING, format='%(asctime)s %(message)s')
sql = "SELECT achid, stamp FROM wwspost.news WHERE posted='0' and type='guildAchievement'"
info = x.execute(sql)
numcheck = int(x.rowcount)
if numcheck > 0:
data = x.fetchall()
for row in data:
achid = str(row[0])
stamp = str(row[1])
URL = Host + "/wow/achievement/" + achid + "?fields=news&locale=en_US&apikey=" + key
r = requests.get(URL)
c = r.json()
achname = c['title']
POST = "Wiping with Style has completed: %s \n http://www.wowhead.com/achievement=%s #worldofwarcraft #achievement" % (achname,achid)
print POST
logging.warning('Posting: %s' % POST)
try:
os.system('python /var/www/wwsguild/twitter-scripts/posttwit.py -m "%s"' % POST)
except:
print "Error"
raise
fixql = "UPDATE wwspost.news SET posted='1' WHERE stamp =" + stamp
try:
x.execute(fixql)
logging.warning('Updating: %s' % fixql)
conn.commit()
except mdb.Error, e:
try:
print "MySQL Error [%d]: %s" % (e.args[0], e.args[1])
except IndexError:
print "MySQL Error: %s" % str(e)
conn.rollback()
conn.close()