Created
October 19, 2011 15:27
-
-
Save apg/1298629 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from com.meetup.base.util import Web, U | |
import uuid | |
import random | |
def coin(): | |
return random.randint(0, 1) == 1 | |
def uuids(): | |
while True: | |
yield str(uuid.uuid4()) | |
def ids(): | |
while True: | |
yield str(random.randint(100921, 209129)) | |
def mk_choices(choices): | |
def _inner(): | |
while True: | |
yield random.choice(choices) | |
return _inner | |
mobile = mk_choices(["ipad", "android", "android_mobile", "other", None]) | |
pagename = mk_choices(["group_home", "member_home", "account", "find", "home", "what_ever", "does_not_matter"]) | |
def sign(url, info, ts): | |
return U.signUrl(url, Web.mapToCgiString(info), None, ts) | |
def mk_gen(base, ud, id, mo, pg): | |
while True: | |
pn = pg.next() | |
values = {'link_id': ud.next(), 'page_name': pn} | |
if pn == 'group_home': | |
values['chapter_id'] = id.next() | |
if coin(): | |
values['member_id'] = id.next() | |
if coin() and 'chapter_id' in values: | |
values['chapter_member_id'] = id.next() | |
if coin(): | |
m = mo.next() | |
if m: | |
values['mobile'] = m | |
yield base + sign('/l/web', values, 3600 * 24 * 365) # valid for a year, we're just testing no biggie | |
if __name__ == '__main__': | |
import sys, itertools | |
if len(sys.argv) == 3: | |
count = int(sys.argv[2]) | |
base = sys.argv[1] | |
gen = mk_gen(base, uuids(), ids(), mobile(), pagename()) | |
for url in itertools.islice(gen, count): | |
print url | |
else: | |
print >>sys.stderr, "usage: %s <baseurl> <count>" % sys.argv[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment