-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
652 additions
and
28 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
week4/phone_challenge_generator/generate_phone_challenge.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/local/bin/python3 | ||
|
||
import random | ||
|
||
def phone_number(): | ||
country_code = str(random.choice([1, 44])) # North American or UK numbers | ||
country_code = random.choice(['', country_code, '+' + country_code]) | ||
area_code = random.sample(range(10), 3) | ||
prefix = random.sample(range(10), 3) | ||
line = random.sample(range(10), 4) | ||
|
||
parens = random.choice([True, False]) | ||
linesep = random.choice([' ', '.', '-']) | ||
areasep = random.choice([' ', '']) if parens else random.choice([' ', linesep]) | ||
|
||
if parens: | ||
area_code = ['('] + area_code + [')'] | ||
|
||
if country_code != '': | ||
country_code = country_code + areasep | ||
|
||
whole = [country_code] + area_code + [areasep] + prefix + [linesep] + line | ||
return ''.join(map(str, whole)) | ||
|
||
def shuffled(filename): | ||
lines = [] | ||
with open(filename) as f: | ||
for line in f: | ||
if len(line) > 1: # exclude blank lines | ||
lines.append(line) | ||
random.shuffle(lines) | ||
return lines | ||
|
||
def insert_random_numbers(line): | ||
words = line.split(' ') | ||
for i in range(len(words)): | ||
if random.random() < 0.03: # 3% chance of inserting a number after each word | ||
words.insert(i, phone_number()) | ||
line = ' '.join(words) | ||
return line | ||
|
||
if __name__ == '__main__': | ||
for line in shuffled('plaintext.txt'): | ||
print(insert_random_numbers(line)) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
for i in {1..2000} | ||
do | ||
echo $i | ||
python3 ./generate_phone_challenge.py | fold > "sample_$i.txt" | ||
done |
Oops, something went wrong.