Added Email address. Updated filter logic to grab all the accounts that aren't @gll accounts. Added print output to mark username changes. Added logic to filter accounts with no address book entries. Hardcoded "United States" to "USA". Rest of countries are first 3 characters of name. Added print output when user has no addressbook.

This commit is contained in:
Dan Dembinski
2021-03-05 09:48:48 -05:00
parent 788521ae99
commit 79d957f398

22
main.py
View File

@@ -42,6 +42,7 @@ class User(Base):
FirstName = Column(String) FirstName = Column(String)
LastName = Column(String) LastName = Column(String)
IsDeleted = Column(BOOLEAN) IsDeleted = Column(BOOLEAN)
Email = Column(String)
class State(Base): class State(Base):
@@ -60,15 +61,17 @@ Session = sessionmaker(bind=engine)
session = Session() session = Session()
# Get list of active users # Get list of active users
for user in session.query(User).filter(User.ID == 14): for user in session.query(User).filter(User.IsDeleted == 0).filter(User.Email.notlike('%gll.com')):
ActiveUser.append([user.ID, user.FirstName, user.LastName]) ActiveUser.append([user.ID, user.FirstName, user.LastName])
# loop through each user in the ActiveUser array. Combine Users First/Last name for the filename and # loop through each user in the ActiveUser array. Combine Users First/Last name for the filename and
# the first letter/last name combo for username # the first letter/last name combo for username
for each in ActiveUser: for each in ActiveUser:
# if session.query(Address).filter(UserAddress.UserId == each[0]).first() is not None:
FileName = each[1] + ' ' + each[2] FileName = each[1] + ' ' + each[2]
UserName = each[1][0]+each[2] UserName = (each[1][0]+each[2]).upper()
print('====================='+FileName+'========================')
# Setup XLS workbook and sheet # Setup XLS workbook and sheet
wb = xlwt.Workbook() wb = xlwt.Workbook()
@@ -98,10 +101,12 @@ for each in ActiveUser:
for ua in session.query(UserAddress).filter(UserAddress.UserId == each[0]): for ua in session.query(UserAddress).filter(UserAddress.UserId == each[0]):
UserAddressID.append(ua.AddressId) UserAddressID.append(ua.AddressId)
for aid in UserAddressID: for aid in UserAddressID:
# for cn in session.query(Address, State, Country).join(State, Address.StateId == State.Id).join(Country, Address.CountryId == Country.Id).filter(Address.Id == aid):
for cn in session.query(Address, State, Country).join(State, Address.StateId == State.Id).join(Country, Address.CountryId == Country.Id).filter(Address.Id == aid): for cn in session.query(Address, State, Country).join(State, Address.StateId == State.Id).join(Country, Address.CountryId == Country.Id).filter(Address.Id == aid):
# Combine all the required fields into one variable for simplicity # Combine all the required fields into one variable for simplicity
AddresssBookLine = UserName, cn[0].CompanyName, cn[0].Line1, cn[0].Line2, cn[0].City, cn[1].StateName, cn[0].PostalCode, cn[2].CountryName, cn[0].PhoneNumber,cn[0].ContactName AddresssBookLine = UserName, cn[0].CompanyName, cn[0].Line1, cn[0].Line2, cn[0].City, cn[1].StateName, cn[0].PostalCode, cn[0].CountryId, cn[0].PhoneNumber, cn[0].ContactName, cn[2].CountryName
# Loop through each row and populate the variable columns with the corresponding AddressBookLine element # Loop through each row and populate the variable columns with the corresponding AddressBookLine element
ws.write(LineCount, 2, AddresssBookLine[0]) ws.write(LineCount, 2, AddresssBookLine[0])
ws.write(LineCount, 3, AddresssBookLine[1]) ws.write(LineCount, 3, AddresssBookLine[1])
@@ -110,12 +115,17 @@ for each in ActiveUser:
ws.write(LineCount, 8, AddresssBookLine[4]) ws.write(LineCount, 8, AddresssBookLine[4])
ws.write(LineCount, 9, AddresssBookLine[5]) ws.write(LineCount, 9, AddresssBookLine[5])
ws.write(LineCount, 10, AddresssBookLine[6]) ws.write(LineCount, 10, AddresssBookLine[6])
ws.write(LineCount, 11, AddresssBookLine[7]) if AddresssBookLine[7] == 1:
ws.write(LineCount, 11, 'USA')
else:
ws.write(LineCount, 11, AddresssBookLine[10][:3])
ws.write(LineCount, 12, AddresssBookLine[8]) ws.write(LineCount, 12, AddresssBookLine[8])
ws.write(LineCount, 13, AddresssBookLine[9]) ws.write(LineCount, 13, AddresssBookLine[9])
LineCount = LineCount + 1 LineCount = LineCount + 1
print(LineCount) print(LineCount)
UserAddressID = [] UserAddressID = []
LineCount = 1 LineCount = 1
wb.save(FileName+'.xls')
wb.save('AddressBooks/'+FileName+'.xls')
else:
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NONE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')