-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulate_rider.py
141 lines (134 loc) · 4.5 KB
/
populate_rider.py
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
import os
import django
from datetime import datetime
from django.contrib.auth import get_user_model
# Set up Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'suivi.settings')
django.setup()
from rider.models import Rider
from parcels.models import Parcel
# User and Rider Details
rider_email = 'njengavictor14@gmail.com'
user_contact = '0711470120'
User = get_user_model()
# Get the User instance
try:
user = User.objects.get(user_contact=user_contact)
except User.DoesNotExist:
print(f"User with contact {user_contact} does not exist.")
exit()
# Get the Rider instance
try:
rider = Rider.objects.get(email=rider_email)
except Rider.DoesNotExist:
print(f"Rider with email {rider_email} does not exist.")
exit()
# Parcel Data
parcels_data = [
{
'receiver_name': 'John Doe',
'receiver_contact': '0723000000',
'pickup_location': 'Westlands, Nairobi',
'delivery_location': 'Kilimani, Nairobi',
'description': 'Documents for approval',
'status': 'in_progress',
'expected_arrival': datetime(2024, 11, 19),
},
{
'receiver_name': 'Jane Smith',
'receiver_contact': '0734000000',
'pickup_location': 'CBD, Nairobi',
'delivery_location': 'Karen, Nairobi',
'description': 'Birthday gift',
'status': 'shipped',
'expected_arrival': datetime(2024, 11, 20),
},
{
'receiver_name': 'Paul Mwangi',
'receiver_contact': '0711000000',
'pickup_location': 'Kilimani, Nairobi',
'delivery_location': 'Mombasa Road, Nairobi',
'description': 'Electronics package',
'status': 'allocated',
'expected_arrival': datetime(2024, 11, 21),
},
{
'receiver_name': 'Lucy Wanjiru',
'receiver_contact': '0722000000',
'pickup_location': 'Langata, Nairobi',
'delivery_location': 'Ruiru, Nairobi',
'description': 'Groceries',
'status': 'pending',
'expected_arrival': datetime(2024, 11, 22),
},
{
'receiver_name': 'George Kamau',
'receiver_contact': '0735000000',
'pickup_location': 'Thika, Nairobi',
'delivery_location': 'Westlands, Nairobi',
'description': 'Books',
'status': 'arrived',
'expected_arrival': datetime(2024, 11, 17),
},
{
'receiver_name': 'Ann Achieng',
'receiver_contact': '0713000000',
'pickup_location': 'Roysambu, Nairobi',
'delivery_location': 'Parklands, Nairobi',
'description': 'Household items',
'status': 'in_progress',
'expected_arrival': datetime(2024, 11, 18),
},
{
'receiver_name': 'Tom Odhiambo',
'receiver_contact': '0724000000',
'pickup_location': 'Kenyatta Market, Nairobi',
'delivery_location': 'CBD, Nairobi',
'description': 'Clothing items',
'status': 'pending',
'expected_arrival': datetime(2024, 11, 19),
},
{
'receiver_name': 'Faith Njeri',
'receiver_contact': '0736000000',
'pickup_location': 'Kasarani, Nairobi',
'delivery_location': 'Embakasi, Nairobi',
'description': 'Electronics',
'status': 'shipped',
'expected_arrival': datetime(2024, 11, 20),
},
{
'receiver_name': 'James Kariuki',
'receiver_contact': '0719000000',
'pickup_location': 'Lavington, Nairobi',
'delivery_location': 'Kikuyu, Nairobi',
'description': 'Furniture',
'status': 'arrived',
'expected_arrival': datetime(2024, 11, 17),
},
{
'receiver_name': 'Grace Wambui',
'receiver_contact': '0728000000',
'pickup_location': 'Gikambura, Nairobi',
'delivery_location': 'Ngong Road, Nairobi',
'description': 'Perishables',
'status': 'allocated',
'expected_arrival': datetime(2024, 11, 21),
},
]
# Add Parcels to Database
for idx, data in enumerate(parcels_data, start=1):
Parcel.objects.create(
sender=user, # Use User instance here
sender_contact=user.user_contact,
receiver_name=data['receiver_name'],
receiver_contact=data['receiver_contact'],
pickup_location=data['pickup_location'],
delivery_location=data['delivery_location'],
description=data['description'],
status=data['status'],
tracking_number=f"TRK{idx:04d}",
expected_arrival=data['expected_arrival'],
)
print(f"Added parcel {idx} for {data['receiver_name']}")
print("Finished populating parcels.")