Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import MySQLdb
import datetime
connection = MySQLdb.connect(host="127.0.0.1", user="root", db="test_db")
date_published = datetime.datetime(year=2001, month=1, day=1)
one_hour = datetime.timedelta(hours=1)
title = "This is a sample title"
content = """
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum.
"""
cursor = connection.cursor()
num_articles = 250000
for n in xrange(1, num_articles):
date_published += one_hour
is_published = bool(n % 6)
new_base_article_sql = """
INSERT INTO base_article (id, date_published, title, content, is_published)
VALUES ({id}, '{date_published}', '{title}', '{content}', {is_published})
""".format(
id=n, date_published=date_published.isoformat(), title=title, content=content, is_published=is_published)
cursor.execute(new_base_article_sql)
connection.commit()
if not bool(n % 10):
issue_slug = date_published.strftime("%Y%m")
new_mag_article_sql = """
INSERT INTO mag_article (basearticle_ptr_id, issue_slug, rubric)
VALUES ({id}, '{issue_slug}', '{rubric}')
""".format(id=n, issue_slug=issue_slug, rubric='Some Rubric')
cursor.execute(new_mag_article_sql)
connection.commit()
cursor.close()
connection.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment