-
-
Save DadKeats/47211ec8249d1d7a3bfe319a4f0b3b10 to your computer and use it in GitHub Desktop.
gen_data.py
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 __future__ import print_function | |
import sys | |
import datetime | |
import random | |
def main(n): | |
start = -86400*365*20 | |
end = 86400*365 | |
filename = 'testdata.txt' | |
with open(filename, 'w') as fp: | |
now = datetime.datetime.now() | |
for i in range(n): | |
d = datetime.timedelta(seconds=random.randint(start, end)) | |
nd = now + d | |
fp.write(nd.strftime("%d/%m/%Y %H:%M:%S")+'\n') | |
print('generate finish {}'.format(filename)) | |
if __name__ == '__main__': | |
if not(len(sys.argv)==2 and sys.argv[1].isdigit()): | |
print('bad input, argument must be number\n') | |
exit() | |
n = int(sys.argv[1]) | |
main(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment