Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Be able to work with a set of data in development
When working on the site, it is helpful to have a large sample of data to work from, so provide a full copy of my own tshirt wearings.
- Loading branch information
Showing
7 changed files
with
3,145 additions
and
1 deletion.
There are no files selected for viewing
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
Empty file.
Empty file.
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,32 @@ | ||
import csv | ||
from django.core.management.base import BaseCommand | ||
|
||
from hasworn.wearers.models import Wearer | ||
from hasworn.clothing.models import Clothing, Wearing, Worn | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Import wearings from a CSV file' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('csv_file') | ||
|
||
def handle(self, *args, **options): | ||
with open(options['csv_file']) as handle: | ||
reader = csv.DictReader(handle) | ||
for row in reader: | ||
print(row) | ||
wearer = Wearer.objects.get(username = row['wearer']) | ||
clothing, _ = Clothing.objects.get_or_create( | ||
name = row['name'], | ||
slug = row['slug'], | ||
created_by = wearer, | ||
) | ||
worn, _ = Worn.objects.get_or_create( | ||
clothing = clothing, | ||
wearer = wearer, | ||
) | ||
wearing = Wearing.objects.get_or_create( | ||
worn = worn, | ||
day = row['date'], | ||
) |
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
#!/usr/bin/env -S bash -euo pipefail | ||
|
||
./compose run app python manage.py "$@" | ||
declare -a env_vars | ||
|
||
[ -n "${DJANGO_SUPERUSER_PASSWORD:-}" ] \ | ||
&& env_vars+=(-e DJANGO_SUPERUSER_PASSWORD=$DJANGO_SUPERUSER_PASSWORD) | ||
|
||
./compose run \ | ||
"${env_vars[@]}" \ | ||
app python manage.py "$@" |
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
import csv | ||
import os | ||
import requests | ||
from bs4 import BeautifulSoup | ||
from dateutil.parser import parse | ||
|
||
with open('wearings.csv', 'w') as handle: | ||
writer = csv.DictWriter( | ||
handle, | ||
fieldnames=['date', 'wearer', 'slug', 'name'], | ||
) | ||
writer.writeheader() | ||
|
||
for year in range(2012, 2022): | ||
req = requests.get('http://norm.hasworn.com/%s/' % year) | ||
soup = BeautifulSoup(req.content, 'html.parser') | ||
for wearing in soup.select('ul.month li'): | ||
slug = os.path.basename(wearing.select('a')[0]['href']) | ||
shirt, when = wearing.select('b') | ||
date = parse(when.text) | ||
writer.writerow({ | ||
'date': date.date(), | ||
'wearer': 'norm', | ||
'name': shirt.text, | ||
'slug': slug, | ||
}) |