Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import csv
  4. import io
  5. import os
  6. from email.mime.multipart import MIMEMultipart
  7. from email.mime.text import MIMEText
  8. from io import StringIO
  9.  
  10. import boto3
  11. import psycopg2
  12. from botocore.exceptions import ClientError
  13.  
  14. import replace as rep
  15.  
  16. LOW = 30.0
  17. NEUTRAL = 70.0
  18.  
  19. CAT = ['OTHERS', 'HSS', 'UTILS', 'TBD', 'IT']
  20.  
  21. tables_order = ['properties', 'tenants', 'leases', 'managers', 'tenant_area',
  22. 'budget', 'tenant_property_occupied_area', 'tenant_client_occupied_area', 'schedule']
  23.  
  24. tables_fields = {
  25. 'leases': ['property_id', 'lease_id', 'break_option', 'charges_amount', 'currency', 'debtor', 'end_date', 'erv_pa', 'floor_area', 'floor_index', 'floor_name', 'lease_status', 'occupational_status', 'rent_amount', 'start_date', 'tenant_id', 'tenant_name'],
  26. 'tenants': ['tenant_id', 'tenant_name', 'address', 'total_area', 'debtor', 'currency', 'mobile_phone', 'direct_phone', 'phone', 'contact_name', 'mail', 'property_id'],
  27. 'properties': ['property_id', 'comment', 'is_listed', 'property_name', 'address', 'total_area', 'debtor', 'rent_amount', 'charges_amount', 'currency', 'client_name', 'year_constructed', 'budget_used', 'budget_used_date', 'annual_budget', 'year_last_refurbished', 'latitude', 'longitude'],
  28. 'managers': ['property_id', 'name', 'role', 'mail', 'phone', 'direct_phone', 'mobile_phone'],
  29. 'tenant_area': ['property_id', 'tenant_id', 'area', 'rent_amount', 'rent_exposure', 'area_exposure'],
  30. 'budget': ['property_id', 'category', 'budget'],
  31. 'tenant_property_occupied_area': ['tenant_id', 'property_id', 'area'],
  32. 'tenant_client_occupied_area': ['tenant_id', 'client_name', 'area'],
  33. 'schedule': ['Property Ref', 'client_parent_ref', 'Client Ref', 'Client Name', 'Property Name', 'Property Town', 'vat_opted', 'Unit ref', 'Unit Name', 'Tenant Ref', 'Tenant', 'property_type_code', 'Property Manager', 'property_status_code', 'lease ref', 'Lease status', 'ref', 'passing_rent', 'annual_s_c', 'Lease years', 'Lease months', 'Lease days', 'Monthly Rent', 'term_start_date', 'term_end_date', 'next_review_date', 'review_basis', 'outside_1954_act', 'holding_over', 'expiry_date', 'managed_by', 'valuation_date', 'valuation_amount', 'floor_area', 'prime_record', 'measured_in', 'comments', 'credit_controller', 'valuation_effective_date', 'client_type', 'CF team', 'FM team', 'PM team', 'Health & Safety', 'SC auditors', 'Utility recovery', 'Debtor ref- current tenancy', 'Debtor name', 'tenancy.start_date', 'occupation_start_date', 'Review frequency', 'breach status', 'Erv_Psf']
  34. }
  35.  
  36.  
  37. temp2nd_lst = ['95560','2502','21489','660133','921010','580000','921600','673301','3953','3751','2514','4900']
  38.  
  39. class Service:
  40.  
  41. def __init__(self, dao):
  42. self.dao = dao
  43.  
  44. def process(self):
  45. print('Starting')
  46.  
  47. exceptions = io.StringIO()
  48. is_there_exceptions = False
  49.  
  50. properties_area_and_rent = {}
  51.  
  52. try:
  53.  
  54. properties_ids = []
  55.  
  56. for table_name in tables_order:
  57. print(table_name)
  58. with open('/home/andykw/cloned_projects/dadoo/dadoo-ingest-repmdata/mockdata_fr/' + table_name + '.csv', 'r') as file:
  59. # it opens csv files in the directory
  60. s = file
  61. if os.environ['ORIGIN'] == 'ie':
  62. delimiter = ';'
  63. else:
  64. delimiter = ','
  65. reader = csv.DictReader(s, delimiter=delimiter)
  66. for row in reader:
  67. if table_name == 'properties':
  68. if row['property_id'] not in properties_ids:
  69. print('toto')
  70. continue
  71. elif table_name == 'tenants':
  72. # The condition above
  73. # check if the name of the table is tenants
  74. # if it is the case, the if are doing their work
  75. print('tato')
  76. if row.get('property_id') == '2502':
  77. row.update({'property_id': '95560'})
  78. elif row.get('property_id') == '21489':
  79. row.update({'property_id': '2502'})
  80. elif row.get('property_id') == '660133':
  81. row.update({'property_id': '21489'})
  82. elif row.get('property_id') == '921010':
  83. row.update({'property_id': '660133'})
  84. elif row.get('property_id') == '580000':
  85. row.update({'property_id': '921010'})
  86. elif row.get('property_id') == '921600':
  87. row.update({'property_id': '580000'})
  88. elif row.get('property_id') == '673301':
  89. row.update({'property_id': '921600'})
  90. elif row.get('property_id') == '3953':
  91. row.update({'property_id': '673301'})
  92. elif row.get('property_id') == '3751':
  93. row.update({'property_id': '3953'})
  94. elif row.get('property_id') == '2514':
  95. row.update({'property_id': '3751'})
  96. elif row.get('property_id') == '4900':
  97. row.update({'property_id': '2514'})
  98. elif row.get('property_id') == '21065':
  99. row.update({'property_id': '4900'})
  100. self.dao.insert(table_name,
  101. clean(row), tables_fields[table_name])
  102.  
  103.  
  104. d = self.dao.get_most_recent_date_modified(tables_order)
  105. self.dao.insert('settings',
  106. {'date': d, 'name': 'data_date'}, ['date', 'name'])
  107. except Exception as e:
  108. print(e)
  109.  
  110. if is_there_exceptions:
  111. print('toto')
  112.  
  113. print('Finished')
  114.  
  115. properties_ids = []
  116. temp_1st_lst = ['2502','21489','660133','921010','580000','921600','673301','3953','3751','2514','4900','21065']
  117. temp_2nd_lst = ['95560','2502','21489','660133','921010','580000','921600','673301','3953','3751','2514','4900']
  118.  
  119. i_temp = 1
  120. if table_name == 'tenants':
  121. for prop_id in temp_1st_lst:
  122. row.update({'property_id': temp_2nd_lst[i_temp]})
  123. i_temp = += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement