Created
January 15, 2015 00:15
-
-
Save anonymous/85059754feeff0ed3085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------ | |
-- CONFIG -- | |
------------ | |
output="%s | %s | %s" -- First %s is amount (no $ sign) | |
-- Second %s is name | |
-- Third %s is message ('No message' if none) | |
waitTime=60 -- Time between grabbing new data | |
outputFile="out.txt" -- Output filename | |
---------------- | |
-- END CONFIG -- | |
---------------- | |
htmlTemplate=[[ | |
<html> | |
<head> | |
<title>asdf</title> | |
<meta http-equiv="refresh" content="60"> | |
</head> | |
<body> | |
<!-- background-image: url("http://www.f-covers.com/cover/thick-and-thin-dark-grey-stripes-pattern-facebook-cover-timeline-banner-for-fb.jpg"); --> | |
<style> | |
.bkg { | |
z-index: -1; | |
left: 0px; | |
top: 0px; | |
height: 20px; | |
line-height: 20px; | |
width: auto; | |
margin-left: 15px; | |
margin-right: 15px; | |
text-align: center; | |
color: #FFFFFF; | |
font-family: "Trebuchet MS", Helvetica, sans-serif; | |
font-size: 16px; | |
} | |
.total { | |
font-family: "Trebuchet MS", Helvetica, sans-serif; | |
font-size: 20px; | |
} | |
</style> | |
<div class="bkg"> | |
%s - <span class="total">%s of %s</span> | |
</div> | |
</body>]] | |
lastDonation="" | |
require"socket" | |
function getData() | |
return io.popen("curl -s http://www.gofundme.com/aveline"):read'*a' | |
end | |
while true do | |
data=getData() | |
done=false | |
if data then | |
d={} | |
for line in data:gmatch("[^\n]+") do | |
if line:match('<div class="damt txt1"><span>%$</span>(%d+)</div>') then | |
d.amt=line:match('<div class="damt txt1"><span>%$</span>(%d+)</div>') | |
elseif line:match('<div class="dname">(.+)</div>') then | |
d.name=line:match('<div class="dname">(.+)</div>') | |
elseif line:match('<div class="dcom">(.+)</div>') then | |
d.msg=line:match('<div class="dcom">(.+)</div>') | |
elseif line:match('</span>(.+)<span class="of"> of</span><span class="goal"> (.+)</span>') then | |
d.have,d.total=line:match('</span>(.+)<span class="of"> of</span><span class="goal"> (.+)</span>') | |
end | |
if d.name and d.amt and not d.msg then | |
d.msg="No message" | |
end | |
if d.name and d.amt and d.msg and not done then | |
done=true | |
print(d.name.."|"..d.amt) | |
if lastDonation~=d.name then | |
print'a' | |
lastDonation=d.name | |
local file=io.open('/var/www/html/out.txt',"w") | |
file:write(d.name.." has donated $"..d.amt) | |
file:close() | |
local file=io.open('/var/www/html/out.html','w') | |
file:write(htmlTemplate:format(d.name.." has donated $"..d.amt,d.have,d.total)) | |
file:close() | |
end | |
end | |
end | |
--[[if amount then | |
print("parsed") | |
if not name==lastDonation then | |
lastDonation=name | |
local file=io.open(outputFile,"a") | |
file:write(output:format(amount,name,message)) | |
file:close() | |
end | |
else | |
print("not parsed end") | |
end]] | |
end | |
socket.select(nil,nil,waitTime) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment