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"
if (args.realm): Realm = args.realm else: Realm = raw_input('Realm:') if (args.guild): Guild = args.guild else: Guild = raw_input('Guild Name:') GuildName = urllib.quote(Guild) URL = Host + "/wow/guild/" + Realm + "/" + GuildName + "?fields=news&locale=en_US&apikey=" + key logging.debug(URL) r = requests.get(URL) c = r.json() d = json.dumps(c, sort_keys=True, indent=0) x.execute("SET NAMES 'utf8'") exql = "SELECT stamp FROM wwspost.news" existing = x.execute(exql) data = str(x.fetchall()) try: status = c['status'] reason = c['reason'] logging.warning(reason) sys.exit() except KeyError: pass try: for results in c['news']: if results['type'] == "playerAchievement":
import os, logging import MySQLdb as mdb from connection import conn,x logging.basicConfig(filename='/var/log/guildinfo.log', level=logging.WARNING, format='%(asctime)s %(message)s') sql = "SELECT a.post_id, a.post_text,a.topic_id, b.username FROM wip1310308551954.phpbb_posts a INNER JOIN wip1310308551954.phpbb_users b on a.poster_id = b.user_id WHERE a.forum_id=19 AND a.post_tweeted=0 and a.post_subject not like 'Re:%'" get_data = x.execute(sql) numcheck = int(x.rowcount) if numcheck > 0: data = x.fetchall() for row in data: post_id = row[0] topic_id = row[2] post_text = row[1] poster = row[3] name_size = len ( poster ) allowed_size = ( 135 - name_size ) text = post_text[:allowed_size] tweet = post_text + " - " + poster try: os.system('python /var/www/wwsguild/twitter-scripts/posttwit.py -m "%s"' % tweet) addql = "INSERT INTO wip1310308551954.phpbb_posts (topic_id,forum_id,post_text,poster_id,poster_ip,post_username,post_subject,post_checksum,bbcode_bitfield,bbcode_uid,post_edit_reason,post_time,post_tweeted) VALUES ('%s',19,'Tweeted','111','127.0.0.1','','Reply','5d782974d96f25a7f333f51b81c550ca','','pqm87p0d','',UNIX_TIMESTAMP(NOW()),1)" % topic_id upql = "UPDATE wip1310308551954.phpbb_posts SET post_tweeted=1 WHERE post_id=%s" % post_id try: x.execute(addql) x.execute(upql) conn.commit() except IndexError:
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') x.execute("SET NAMES 'utf8'") sql = "SELECT chrname, itemid, stamp FROM wwspost.news WHERE posted='0' and type in ('itemPurchase','itemLoot','itemCraft')" info = x.execute(sql) numcheck = int(x.rowcount) if numcheck > 0: data = x.fetchall() for row in data: charname = row[0] enc = unicode(charname) itemid = str(row[1]) stamp = str(row[2]) URL = Host + "/wow/item/" + str(itemid) + "?locale=en_US&apikey=" + key r = requests.get(URL) c = r.json() itemname = c['name'] POST = '%s acquired %s http://www.wowhead.com/item=%s #WoW #Warcraft' % (enc,itemname,itemid) logging.warning('Posting: %s' % POST) try: os.system('python /var/www/wwsguild/twitter-scripts/posttwit.py -m "%s"' % POST.encode("utf-8")) except: print "Error" raise fixql = "UPDATE wwspost.news SET posted='1' WHERE stamp =" + stamp
Realm = args.realm else: Realm = raw_input('Realm:') if (args.guild): Guild = args.guild else: Guild = raw_input('Guild Name:') GuildName = urllib.quote(Guild) URL = Host + "/wow/guild/" + Realm + "/" + GuildName + "?fields=members&locale=en_US&apikey=" + key logging.debug(URL) r = requests.get(URL) c = r.json() d = json.dumps(c, sort_keys=True, indent=0) x.execute("SET NAMES 'utf8'") levelql = "SELECT name, level FROM wwspost.members" cur_level = x.execute(levelql) levels = dict(x.fetchall()) grankql = "SELECT name, g_rank FROM wwspost.members" cur_rank = x.execute(grankql) rank = dict(x.fetchall()) classes = { 1: 'Warrior', 2: 'Paladin', 3: 'Hunter', 4: 'Rogue', 5: 'Priest', 6: 'Death Knight', 7: 'Shaman', 8: 'Mage',