Created
March 11, 2018 09:07
-
-
Save AnuragRamdasan/c537855ec2f5f353f52dec7823b322f7 to your computer and use it in GitHub Desktop.
Scripts to automate invoice downloads
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
;(function($, undefined) { | |
var scraper = { | |
iterator: '._3xMk0', | |
data: { | |
date: { sel: '._2fkm7 span', method: 'text' }, | |
restaurant: {sel: '._3h4gz', method: 'text'}, | |
id: {sel: '._2uT6l', method: 'text'}, | |
price: {sel: '._3Hghg', method: 'text'} | |
}, | |
params: { | |
done: function(data){ | |
data.forEach(function(d) { | |
d.date = d.date.replace('Delivered on', '').replace('Cancelled on', '').trim() | |
d.id = d.id.split('#')[1].split("|")[0].trim() | |
}) | |
artoo.s.pushTo('order_list', data); | |
} | |
} | |
}; | |
// Start the scraper | |
artoo.log.debug('Starting the scraper...'); | |
var ui = new artoo.ui(); | |
ui.$().append('<div style="position:fixed; top:35px; left:25px; background-color: #000; color: #FFF; z-index:1000">Scraping in progress... this may take a few minutes! DO NOT CLICK THE EXTENSION AGAIN!</div>'); | |
artoo.autoExpand({ | |
elements: '._3xMk0', | |
expand: function($) { | |
$('._2pWZz').simulate('click') | |
}, | |
canExpand: '._2pWZz', | |
throttle: 5000, | |
done: function() { | |
console.log('Done expanding posts 100 times!'); | |
var swiggy = artoo.scrape(scraper); | |
ui.kill(); | |
artoo.saveCsv([].concat.apply([], artoo.s.get('order_list')), { | |
filename: 'order-history.csv' | |
}); | |
artoo.s.remove('order_list'); | |
} | |
}); | |
}).call(this, artoo.$); |
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
windows = [] | |
index = 0 | |
slice = 2 | |
function downloadInvoice() { | |
console.log(index) | |
if(index < trips.length) { | |
currTrips = trips.slice(index, index + slice) | |
console.log(currTrips) | |
currTrips.forEach(function(t) { | |
var url = "https://www.swiggy.com/invoice/download/" + t | |
var w = window.open(url,'','width=,height=,resizable=no') | |
windows.push(w) | |
}) | |
setTimeout(function() { | |
windows.forEach(function(w) { | |
w.close() | |
}) | |
index += slice | |
downloadInvoice(trips.slice(index)) | |
}, 9000) | |
} else { | |
return | |
} | |
} | |
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
import csv | |
import sys | |
def write_var(path): | |
var = "var trips = [" | |
with open(path, 'rb') as csvfile: | |
csvfile = csv.reader(csvfile, delimiter=',') | |
ind = 0 | |
for row in csvfile: | |
if row[2] == "": | |
break | |
if ind != 0: | |
var += '"' + row[2] + '",' | |
ind += 1 | |
var += "]" | |
with open("var.txt", 'w') as txt_file: | |
txt_file.write(var) | |
if __name__ == "__main__": | |
path = sys.argv[1] | |
write_var(path) |
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
windows = [] | |
index = 0 | |
slice = 2 | |
function downloadInvoice() { | |
console.log(index) | |
if(index < trips.length) { | |
currTrips = trips.slice(index, index + slice) | |
currTrips.forEach(function(t) { | |
console.log(t) | |
var url = "https://riders.uber.com/trips/" + t | |
var w = window.open(url) | |
windows.push(w) | |
}) | |
setTimeout(function() { | |
windows.forEach(function(w) { | |
w.close() | |
}) | |
index += slice | |
downloadInvoice(trips.slice(index)) | |
}, 9000) | |
} else { | |
return | |
} | |
} |
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
import csv | |
import sys | |
def write_var(path): | |
var = "var trips = [" | |
with open(path, 'rb') as csvfile: | |
csvfile = csv.reader(csvfile, delimiter=',') | |
ind = 0 | |
for row in csvfile: | |
if row[0] == "": | |
break | |
if ind != 0: | |
var += '"' + row[0] + '",' | |
ind += 1 | |
with open("var.txt", 'w') as txt_file: | |
txt_file.write(var) | |
if __name__ == "__main__": | |
path = sys.argv[1] | |
write_var(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment