Last active
May 4, 2017 05:28
-
-
Save Tester2009/c500ff7cbb7d2a77842fdee076ebb3fa to your computer and use it in GitHub Desktop.
simple way to extract data by using python
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
# Simple Data Extractor | |
# Made by Tester2009. https://github.com/alepcat1710 | |
# May 4, 2017 | |
# Ver 1.2 | |
import getopt, sys, os, json, urllib2 | |
from urlparse import urlparse | |
def main(): | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], "hu:v", ["url=", "version", "help"]) | |
except getopt.GetoptError as err: | |
print str(err) # will print something like "option -a not recognized" | |
sys.exit(2) | |
for o, a in opts: | |
if o in ("-u", "--url"): | |
os.system('clear') | |
print "Data Extractor" | |
path = "wp-json/wp/v2/users" | |
yis_url = "" | |
if urlparse(a).netloc != '': | |
# diz got http or https | |
yis_url = urlparse(a).scheme + '://' + urlparse(a).netloc + '/' + path | |
else: | |
# diz nutz. | |
yis_url = 'http://' + urlparse(a).path + '/' + path | |
print yis_url | |
print " " | |
data = json.load(urllib2.urlopen(yis_url)) | |
for i in range(len(data)): | |
print data[i]['id'] | |
print data[i]['slug'] | |
print data[i]['name'] | |
print data[i]['description'] | |
print " " | |
elif o in ("-v", "--version"): | |
os.system('clear') | |
print "Data Extractor" | |
print "Version 1.2" | |
print "by https://fb.com/Tester2009" | |
elif o in ("-h", "--help"): | |
os.system('clear') | |
print "Data Extractor" | |
print "python " +sys.argv[0]+" -u url" | |
sys.exit() | |
else: | |
assert False, "unhandled option" | |
if len(sys.argv)<2: | |
os.system('clear') | |
print "Data Extractor" | |
print "python " +sys.argv[0]+" -u url" | |
sys.exit() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment