Advertisement
Guest User

Untitled

a guest
Nov 30th, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.49 KB | None | 0 0
  1. #!/python/Python-2.7.2
  2. #Steam64 ID - 76561198041707719
  3. import urllib
  4. import cgi, cgitb
  5. import itertools
  6. import urllib2
  7. import time
  8. from datetime import datetime
  9. from bs4 import BeautifulSoup
  10. from flask import Flask, jsonify, render_template, redirect
  11. import requests
  12. import json
  13. import xml.etree.ElementTree as ET
  14. from xml.dom.minidom import parseString
  15. import sys
  16.  
  17. API_KEY = 'XXX'
  18. API_BASEURL = 'http://api.steampowered.com/'
  19. API_GET_FRIENDS = API_BASEURL + 'ISteamUser/GetFriendList/v0001/?key='+API_KEY+'&steamid='
  20. API_GET_SUMMARIES = API_BASEURL + 'ISteamUser/GetPlayerSummaries/v0002/?key='+API_KEY+'&steamids='
  21. PROFILE_URL = 'http://steamcommunity.com/profiles/'
  22. phisherusers = ''
  23. steamIDs = []
  24. myFriends = []
  25. phisherids = []
  26. cgitb.enable()
  27. form = cgi.FieldStorage()
  28. steeam = form.getfirst('steamid')
  29.  
  30. class steamUser:
  31.     def __init__(self, name, steamid, picture, profileurl, profilestate, isPhisher):
  32.         self.name = name
  33.         self.steamid = steamid
  34.         self.isPhisher = isPhisher
  35.         self.profileurl = profileurl
  36.         if profilestate == 0:
  37.             self.profilestate = '<span style=\"color:#616161\";>(Offline)</span>'
  38.             self.picture = '<img class = \"offline\" src=\"' + picture + '\" title = \"\" alt = \"\">'
  39.         elif profilestate == 1:
  40.             self.profilestate = '<span style=\"color:#006EFF\";>(Online)</span>'
  41.             self.picture = '<img class = \"border\" src=\"' + picture + '\" title = \"\" alt = \"\">'
  42.         elif profilestate == 2:
  43.             self.profilestate = '<span style=\"color:#006EFF\";>(Busy)</span>'
  44.             self.picture = '<img class = \"border\" src=\"' + picture + '\" title = \"\" alt = \"\">'
  45.         elif profilestate == 3:
  46.             self.profilestate = '<span style=\"color:#006EFF\";>(Away)</span>'
  47.             self.picture = '<img class = \"border\" src=\"' + picture + '\" title = \"\" alt = \"\">'
  48.         elif profilestate == 4:
  49.             self.profilestate = '<span style=\"color:#006EFF\";>(Snooze)</span>'
  50.             self.picture = '<img class = \"border\" src=\"' + picture + '\" title = \"\" alt = \"\">'
  51.         elif profilestate == 5:
  52.             self.profilestate = '<span style=\"color:#006EFF\";>(Looking to Trade)</span>'
  53.             self.picture = '<img class = \"border\" src=\"' + picture + '\" title = \"\" alt = \"\">'
  54.         else:
  55.             self.profilestate = '<span style=\"color:#006EFF\";>(Looking to Play)</span>'
  56.             self.picture = '<img class = \"border\" src=\"' + picture + '\" title = \"\" alt = \"\">'
  57.    
  58.     def setPhisherStatus(self, phisher):
  59.         self.isPhisher = phisher
  60.        
  61.     def toString(self):
  62.         return '<div id = \"phisher-profile\" style = \"width: 33%; float: left; display: block;  margin-left: auto; margin-right: auto;\"><h3 style = \"font-size: 30px\">' + self.picture + '</br> </br>' + self.name + '</br>' + self.profilestate + '</br>' + 'Steam ID: ' + self.steamid + '</br>' + '<a href=\"' + self.profileurl + '\">Steam Profile' + '</a></br></br>' + '</h3></div>' + ''
  63.        
  64. def getFriendList(steamid):
  65.     for i in range(0, 3):
  66.         try:
  67.             r = requests.get(API_GET_FRIENDS+steamid, timeout=5)
  68.         except:
  69.             continue
  70.         data = r.json()
  71.         for friend in data['friendslist']['friends']:
  72.             steamIDs.append(friend['steamid'])
  73.         return grabPhishers(steamIDs)
  74.     return 'Unable to grab your friend\'s list, please try your request again.'
  75.    
  76. def grabPhishers(ids):
  77.     global phisherusers
  78.     for l in chunksiter(ids, 50):
  79.         sids = ','.join(map(str, l))
  80.         if not isPhisher(sids):
  81.             return 'Connection Error: Please try your request again.'
  82.     #remove duplicates
  83.     for fri in myFriends:
  84.         if fri.isPhisher:
  85.             phisherids.append(fri.steamid)
  86.             phisherusers = phisherusers + fri.toString()
  87.     if phisherusers == '':
  88.         return 'User has no phishers!'
  89.     return phisherusers
  90.    
  91. def chunksiter(l, chunks):
  92.     i,j,n = 0,0,0
  93.     rl = []
  94.     while n < len(l)/chunks:        
  95.         rl.append(l[i:j+chunks])        
  96.         i+=chunks
  97.         j+=j+chunks        
  98.         n+=1
  99.     return iter(rl)
  100.    
  101. def isPhisher(sids):
  102.     for jk in range(0, 3):
  103.         try:
  104.             r = requests.get(API_GET_SUMMARIES+sids, timeout=5)        
  105.         except:
  106.             continue
  107.         data = r.json();
  108.         for i in range(len(data['response']['players'])):
  109.             steamFriend = data['response']['players'][i]
  110.             n = steamUser(steamFriend['personaname'], steamFriend['steamid'], steamFriend['avatarfull'], steamFriend['profileurl'], steamFriend['personastate'], False)
  111.             if steamFriend['communityvisibilitystate'] and not steamFriend['personastate']:
  112.                 url =  PROFILE_URL+steamFriend['steamid']+'?xml=1'
  113.                 if 'profilestate' not in steamFriend:
  114.                     n.setPhisherStatus(True);
  115.                     #phisherusers = phisherusers + n.toString()
  116.                 for jjk in range(0, 3):
  117.                     try:
  118.                         dat = requests.get(url, timeout=5)
  119.                     except:
  120.                         continue
  121.                     if parseString(dat.text.encode('utf8')).getElementsByTagName('privacyState'):
  122.                         privacy = str(parseString(dat.text.encode('utf-8')).getElementsByTagName('privacyState')[0].firstChild.wholeText)
  123.                         if (privacy == 'private'):
  124.                             n.setPhisherStatus(True)
  125.                             #phisherusers = phisherusers + n.toString()
  126.             elif 'profilestate' not in steamFriend:
  127.                 n.setPhisherStatus(True);
  128.                 #phisherusers = phisherusers + n.toString()
  129.             else:
  130.                 steamprofile = BeautifulSoup(urllib.urlopen(PROFILE_URL+steamFriend['steamid']).read())
  131.                 for row in steamprofile('div', {'class': 'commentthread_comment  '}):
  132.                     comment = row.find_all('div', 'commentthread_comment_text')[0].get_text().lower()
  133.                     if ('phisher' in comment) or ('scammer' in comment):
  134.                         n.setPhisherStatus(True)
  135.                         #phisherusers = phisherusers + n.toString()
  136.             myFriends.append(n);
  137.         return True
  138.     return "Connection Error: Please try your request again."
  139.  
  140. def grabPhisherIDs():
  141.     return ','.join(map(str, phisherids))
  142.  
  143. body=("<html><title>Hello</title>" +
  144.           "<body>" +
  145.           "<div id=\"phisher-users\"></br></br>" +
  146.           "%s" +
  147.           "</br></br>" +
  148.           "</div>" +
  149.           "<div id=\"phisher-ids\" style=\"display: none;\">" +
  150.           "%s" +
  151.           "</div>" +  
  152.           "</body>" +
  153.           "</html>" % (getFriendList(steeam), grabPhisherIDs()))
  154.  
  155. reply=("HTTP/1.1 200 OK\n" +
  156.            "Date: %s\n" +
  157.            "Content-Type: text/html\n" +
  158.            "Content-Length: %s\n" +
  159.            "Connection: close\n" +
  160.            "\n" +
  161.            "%s" % (datetime.datetime.utcnow().isoformat(' '), len(body), body)  )
  162.            
  163.  
  164. print reply
  165. #print "Content-type: text/html\r\n\r\n"
  166. #print "<div id=\"phisher-users\"></br></br>"
  167. #print getFriendList(steeam)
  168. #print "</div>"
  169. #print "<div id=\"phisher-ids\" style=\"display: none;\">"
  170. #print grabPhisherIDs()
  171. #print "</div>"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement