JPiolho

[Minecraft][CC] XFire API

Mar 5th, 2012
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.61 KB | None | 0 0
  1. -- XFire API
  2. -- Version 1.0
  3. -- By JPiolho
  4. -- Feel free to copy and edit as long you credit the original author
  5. -- More Info @ http://bit.ly/zoxn6V
  6.  
  7. local function trim (s)
  8.    return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
  9. end
  10.  
  11. function getGamingHistory(username)
  12.     if http == nil then return nil end
  13.  
  14.     local tbl = {}
  15.  
  16.     local html = http.get("http://www.xfire.com/profile/" .. username)
  17.     if html == nil then return nil end
  18.  
  19.     html = html:readAll()
  20.  
  21.     local s = 0
  22.     local e = 0
  23.     while true do
  24.         s,e = string.find(html,"<td class=\"est_stats_rows_gamecol\">",e+1)
  25.  
  26.         if s == nil or e == nil then break end
  27.  
  28.  
  29.         local s2,e2 = string.find(html,">",e+1)
  30.         local s3,e3 = string.find(html,"</a>",e2+1)
  31.  
  32.         -- Avoid 'Overall Hours'
  33.         if string.sub(html,s2-7,s2) ~= "<strong>" then
  34.             local gamename = string.sub(html,e2+1,s3-1)
  35.  
  36.             table.insert(tbl,gamename)
  37.         end
  38.  
  39.     end
  40.  
  41.     return tbl
  42. end
  43.  
  44. function getGamingRig(username)
  45.     if http == nil then return nil end
  46.  
  47.     local html = http.get("http://www.xfire.com/profile/" .. username)
  48.     if html == nil then return nil end
  49.  
  50.     html = html:readAll()
  51.  
  52.     local tbl = {}
  53.  
  54.     local s,e
  55.     local es,ee
  56.  
  57.     s,e = string.find(html,"<table class=\"gaming_rig\">")
  58.     es,ee = string.find(html,"</table>",e)
  59.  
  60.     local s2,e2
  61.     while true do
  62.         s2,e2 = string.find(html,"<th>",e2)
  63.  
  64.         if s2 == nil or e2 == nil or s2 > es or e2 > ee then break end
  65.  
  66.         local s3,e3 = string.find(html,"</th>",e2)
  67.  
  68.         local key = string.gsub(string.sub(html,e2+1,s3-1),":$","")
  69.  
  70.         local s4,e4 = string.find(html,"<div class=\"gaming_rig_content\">",e3)
  71.         local s5,e5 = string.find(html,"</div>",e4)
  72.  
  73.         tbl[key] = string.sub(html,e4+1,s5-1)
  74.     end
  75.  
  76.     return tbl
  77.  
  78. end
  79.  
  80. function getTotalPlayHours(username)
  81.     if http == nil then return nil end
  82.  
  83.     local html = http.get("http://www.xfire.com/profile/" .. username)
  84.     if html == nil then return nil end
  85.  
  86.     html = html:readAll()
  87.  
  88.     local s,e
  89.  
  90.     s,e = string.find(html,"<table class=\"gameplay_hours_overall overlay_box\">")
  91.  
  92.     local s2,e2 = string.find(html,"<td class=\"est_stats_rows_totalcol\">",e)
  93.     local s3,e3 = string.find(html,"<",e2+1)
  94.  
  95.     return trim(string.gsub(string.gsub(string.sub(html,e2+1,s3-1),"hours",""),"%.",""))
  96. end
  97.  
  98. function getStatus(username)
  99.     if http == nil then return nil end
  100.  
  101.     local html = http.get("http://www.xfire.com/profile/" .. username)
  102.     if html == nil then return nil end
  103.  
  104.     html = html:readAll()
  105.  
  106.     local s,e
  107.  
  108.     s,e = string.find(html,"<span class=\"profile_label\">Status</span>")
  109.  
  110.     local s2,e2 = string.find(html,"<br />",e)
  111.     local s3,e3 = string.find(html,"</p>",e2+1)
  112.  
  113.     return trim(string.sub(html,e2+1,s3-1))
  114. end
Advertisement
Add Comment
Please, Sign In to add comment