-
-
Save 4adamu/efb1a1859bb298b9cebb91eb49a57d50 to your computer and use it in GitHub Desktop.
Fake ID generator
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 requests | |
import BeautifulSoup | |
import sys | |
import time | |
class RandomPerson: | |
def __init__(self): | |
bs = BeautifulSoup.BeautifulSoup(self.get_text()) | |
d = bs.find("div", "address") | |
self.firstname, self.lastname = d.h3.string.rsplit(" ", 1) | |
self.address = d.find("div", "adr").text | |
d = bs.find("div", "extra") | |
cur_attr = None | |
for info in d.findAll("li"): | |
if cur_attr == None: | |
cur_attr = info.text.lower().replace(" ","_").replace("'s","")[:-1] | |
else: | |
setattr(self, cur_attr, info.text) | |
cur_attr = None | |
self.sanitize_params() | |
return | |
def sanitize_params(self): | |
self.birthday = time.strftime("%d/%m/%Y", time.strptime(self.birthday.split("(")[0][:-1], "%B %d, %Y")) | |
self.email_address = self.email_address.replace("This is a real email address.Click here to activate it!", "") | |
self.height = self.height.split("(")[1][:-1] | |
self.weight = self.weight.split("(")[1][:-1] | |
del(self.ssn) | |
del(self.qr_code) | |
def get_text(self): | |
h = requests.get("http://www.fakenamegenerator.com/gen-random-us-us.php") | |
if h.status_code != 200: | |
return -1 | |
return h.text | |
def __str__(self): | |
return "%s %s" % (self.firstname, self.lastname) | |
def to_txt(self): | |
buf = "Name: %s" % str(self) | |
for attr in dir(self): | |
if attr.startswith("__"): | |
continue | |
a = getattr(self, attr) | |
if hasattr(a, "__call__"): | |
continue | |
buf+= "%s: %s\n" % (attr.capitalize(), a) | |
return buf | |
def to_csv(self): | |
buf = "" | |
for attr in dir(self): | |
if attr.startswith("__"): | |
continue | |
a = getattr(self, attr) | |
if hasattr(a, "__call__"): | |
continue | |
buf+= "%s; " % a | |
return buf | |
def to_xml(self): | |
buf = "<person>\n" | |
for attr in dir(self): | |
if attr.startswith("__"): | |
continue | |
a = getattr(self, attr) | |
if hasattr(a, "__call__"): | |
continue | |
buf+= "\t<{0}>{1}</{0}>\n".format(attr, a) | |
buf+= "</person>" | |
return buf | |
def as_windows_user(self, ad=None): | |
fmt = "net user {0} {1} " | |
fmt+= "/active:yes /comment:\"{2}\" " | |
fmt+= "/fullname:\"{3}\" /passwordchg:no " | |
if ad is not None: | |
fmt+= "/domain" | |
fmt+= " /add" | |
return fmt.format (self.firstname[0].lower() + self.lastname.lower(), | |
self.password, self.occupation, str(self)) | |
def as_linux_user(self): | |
fmt = "adduser -c '{1}' -g users {0} && echo -e \"{2}\n{2}\" | passwd " | |
return fmt.format(self.firstname[0].lower() + self.lastname.lower(), | |
self.occupation, | |
self.password) | |
if __name__ == "__main__": | |
if "-txt" not in sys.argv[1:] \ | |
and "-xml" not in sys.argv[1:] \ | |
and "-csv" not in sys.argv[1:]: | |
print "Missing output format (-txt, -xml, -csv)" | |
exit(1) | |
p = RandomPerson() | |
print "Created '%s'"% p | |
if "-txt" in sys.argv[1:]: | |
print p.to_txt() | |
if "-xml" in sys.argv[1:]: | |
print p.to_xml() | |
if "-csv" in sys.argv[1:]: | |
print p.to_csv() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment