Skip to content

Instantly share code, notes, and snippets.

@hugsy
Last active December 14, 2021 00:59
Show Gist options
  • Save hugsy/7458879 to your computer and use it in GitHub Desktop.
Save hugsy/7458879 to your computer and use it in GitHub Desktop.
Fake ID generator
import sys, time, requests, bs4
RANDOM_ID_URL = "http://www.fakenamegenerator.com/gen-random-us-us.php"
class RandomPerson:
def __init__(self):
self.soup = bs4.BeautifulSoup(self.get_page_text(), "lxml")
d = self.soup.find("div", "address")
self.firstname, self.lastname = d.h3.string.rsplit(" ", 1)
self.address = d.find("div", "adr").text.strip()
self.age = int(self.get_element("Age").text.split()[0])
self.email_address = self.get_element("Email Address").text.split()[0]
self.birthday = " ".join(self.get_element("Birthday").text.split()[:3])
self.birthday = time.strftime("%d/%m/%Y", time.strptime(self.birthday, "%B %d, %Y"))
self.username = self.get_element("Username").text
self.password = self.get_element("Password").text
self.website = self.get_element("Website").text
self.occupation = self.get_element("Occupation").text
return
def get_element(self, name):
return self.soup.find("dt", text=name).next_sibling.next_sibling
def get_page_text(self):
h = requests.get(RANDOM_ID_URL)
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)"
sys.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()
@hugsy
Copy link
Author

hugsy commented Nov 19, 2016

Using emacs 😄

@xccvme
Copy link

xccvme commented Dec 14, 2021

how i can use this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment