Created
August 25, 2018 20:03
-
-
Save codl/4ff9f04a207103951323211f45fc13c3 to your computer and use it in GitHub Desktop.
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
import psycopg2 | |
db = psycopg2.connect('postgresql:///mastodon_development') | |
cur = db.cursor() | |
for i in range(500): | |
screenname = "bogus_{}".format(i) | |
email = "bogus_{}@m.codl.fr".format(i) | |
acc_to_follow = 1 | |
try: | |
cur.execute(''' | |
INSERT INTO accounts (username, created_at, updated_at) | |
VALUES (%s, now(), now()) | |
RETURNING id; | |
''', (screenname, )) | |
acc_id = cur.fetchone()[0] | |
cur.execute(''' | |
INSERT INTO users (email, account_id, created_at, updated_at, confirmed_at) | |
VALUES (%s, %s, now(), now(), now()); | |
''', (email, acc_id)) | |
cur.execute(''' | |
INSERT INTO follows (account_id, target_account_id, created_at, updated_at) | |
VALUES (%s, %s, now(), now()); | |
''', (acc_id, acc_to_follow)) | |
db.commit() | |
print("{} created".format(screenname)) | |
except psycopg2.IntegrityError: | |
print("{} already exists".format(screenname)) | |
db.rollback() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment