-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_listings.py
More file actions
286 lines (250 loc) · 9.84 KB
/
generate_listings.py
File metadata and controls
286 lines (250 loc) · 9.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import random
from datetime import date, timedelta
from decimal import Decimal
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand
from django.utils import timezone
from market.models import Category, Item, Sublet
User = get_user_model()
class Command(BaseCommand):
help = "Generate 25 random items and 25 random sublets for testing"
def handle(self, *args, **options):
user, created = User.objects.get_or_create(
username="testuser",
defaults={
"email": "testuser@example.com",
"first_name": "Test",
"last_name": "User",
},
)
if created:
user.set_password("testpassword123")
user.save()
self.stdout.write(self.style.SUCCESS(f"Created test user: {user.username}"))
else:
self.stdout.write(
self.style.SUCCESS(f"Using existing user: {user.username}")
)
categories_data = [
"Art",
"Books",
"Clothing",
"Electronics",
"Furniture",
"Home and Garden",
"Music",
"Other",
"Tools",
"Vehicles",
]
categories = []
for cat_name in categories_data:
category, created = Category.objects.get_or_create(name=cat_name)
categories.append(category)
if created:
self.stdout.write(self.style.SUCCESS(f"Created category: {cat_name}"))
adjectives = [
"Vintage",
"Modern",
"Classic",
"Brand New",
"Like New",
"Gently Used",
"Rare",
"Limited Edition",
"Premium",
"Budget-Friendly",
"Professional",
"Student",
"Portable",
"Compact",
"Spacious",
]
item_types = {
"Art": ["Painting", "Sculpture", "Print", "Drawing", "Poster"],
"Books": ["Textbook", "Novel", "Magazine", "Comic Book", "Reference Book"],
"Clothing": ["Jacket", "Shirt", "Pants", "Dress", "Shoes"],
"Electronics": ["Laptop", "Phone", "Tablet", "Headphones", "Monitor"],
"Furniture": ["Chair", "Desk", "Table", "Bookshelf", "Lamp"],
"Home and Garden": [
"Plant",
"Rug",
"Curtains",
"Kitchen Set",
"Decoration",
],
"Music": ["Guitar", "Keyboard", "Speakers", "Vinyl Record", "Music Stand"],
"Other": ["Bike", "Skateboard", "Game Console", "Camera", "Watch"],
"Tools": ["Toolbox", "Drill", "Hammer Set", "Measuring Tape", "Saw"],
"Vehicles": [
"Bicycle",
"Scooter",
"Skateboard",
"Motorcycle Helmet",
"Car Seat",
],
}
item_descriptions = [
"Great condition, barely used!",
"Perfect for students. Must sell before graduation.",
"Moving out sale - need gone ASAP!",
"Works perfectly, no issues.",
"Excellent quality, well maintained.",
"Amazing deal, don't miss out!",
"Slight wear and tear but fully functional.",
"Like new condition, original packaging included.",
"Used for one semester only.",
"Selling because I upgraded to a newer model.",
]
conditions = [
Item.Condition.NEW,
Item.Condition.LIKE_NEW,
Item.Condition.GOOD,
Item.Condition.FAIR,
]
# generate 25 items
items_created = 0
self.stdout.write(self.style.WARNING("\n=== Generating Items ==="))
for _ in range(25):
category = random.choice(categories)
adjective = random.choice(adjectives)
item_type = random.choice(item_types.get(category.name, ["Item"]))
title = f"{adjective} {item_type}"
description = random.choice(item_descriptions)
# Random price between $5 and $500
price = Decimal(random.uniform(5, 500)).quantize(Decimal("0.01"))
# Random condition
condition = random.choice(conditions)
# Negotiable - 70% chance of being negotiable
negotiable = random.random() < 0.7
# Expires in 30-90 days
days_until_expiry = random.randint(30, 90)
expires_at = timezone.now() + timedelta(days=days_until_expiry)
try:
Item.objects.create(
seller=user,
title=title,
description=description,
price=price,
negotiable=negotiable,
expires_at=expires_at,
condition=condition,
category=category,
)
items_created += 1
self.stdout.write(f"Created item {items_created}: {title} - ${price}")
except Exception as e:
self.stdout.write(self.style.ERROR(f"Error creating item: {str(e)}"))
sublet_adjectives = [
"Cozy",
"Spacious",
"Modern",
"Renovated",
"Charming",
"Bright",
"Quiet",
"Convenient",
"Luxurious",
"Affordable",
]
sublet_types = [
"Studio Apartment",
"1BR Apartment",
"2BR Apartment",
"3BR Apartment",
"Room in Shared Apartment",
"Loft",
"Townhouse",
"House",
]
street_names = [
"Walnut",
"Chestnut",
"Spruce",
"Pine",
"Locust",
"Market",
"Sansom",
"Baltimore",
"Lombard",
"South",
"Arch",
"Race",
]
sublet_descriptions = [
"Perfect location near campus! Walking distance to classes and libraries.",
"Newly renovated with modern appliances. Available for summer sublet.",
"Great for students! Utilities included, close to public transportation.",
"Furnished apartment in a safe, quiet neighborhood. Perfect for studying.",
"Beautiful apartment with lots of natural light. Must see!",
"Ideal for summer internship. Flexible lease terms available.",
"Close to restaurants, shops, and nightlife. Very convenient location.",
"Spacious and clean. Perfect for roommates or single occupant.",
"Pet-friendly building with on-site laundry. Great amenities!",
"Amazing deal for the location! Available immediately.",
]
# generate 25 sublets
sublets_created = 0
self.stdout.write(self.style.WARNING("\n=== Generating Sublets ==="))
for _ in range(25):
adjective = random.choice(sublet_adjectives)
sublet_type = random.choice(sublet_types)
title = f"{adjective} {sublet_type}"
description = random.choice(sublet_descriptions)
# generate random address
street_number = random.randint(100, 4999)
street = random.choice(street_names)
street_address = f"{street_number} {street} St, Philadelphia, PA"
# random beds and baths
beds = random.randint(0, 4) # 0 for studio
baths = random.randint(1, 3)
# random price between $500 and $3000 per month
price = Decimal(random.uniform(500, 3000)).quantize(Decimal("0.01"))
# negotiable - 60% chance of being negotiable
negotiable = random.random() < 0.6
# start date: between now and 90 days from now
days_until_start = random.randint(0, 90)
start_date = date.today() + timedelta(days=days_until_start)
# end date: 1-12 months after start date
months_duration = random.randint(1, 12)
days_duration = months_duration * 30
end_date = start_date + timedelta(days=days_duration)
# listing expires 30 days before start date
# or in 60 days, whichever is sooner
days_until_expiry = min(days_until_start + 30, 60)
if days_until_expiry < 1:
days_until_expiry = 30
expires_at = timezone.now() + timedelta(days=days_until_expiry)
try:
Sublet.objects.create(
seller=user,
title=title,
description=description,
price=price,
negotiable=negotiable,
expires_at=expires_at,
street_address=street_address,
beds=beds,
baths=baths,
start_date=start_date,
end_date=end_date,
)
sublets_created += 1
bed_str = "Studio" if beds == 0 else f"{beds} bed"
self.stdout.write(
f"Created sublet {sublets_created}: {title} - "
f"${price}/mo ({bed_str}, {baths} bath)"
)
except Exception as e:
self.stdout.write(self.style.ERROR(f"Error creating sublet: {str(e)}"))
# summary
self.stdout.write(self.style.SUCCESS("\n=== Summary ==="))
self.stdout.write(
self.style.SUCCESS(f"Successfully created {items_created} items!")
)
self.stdout.write(
self.style.SUCCESS(f"Successfully created {sublets_created} sublets!")
)
self.stdout.write(
self.style.SUCCESS(f"All listings are created by user: {user.username}")
)