Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.20 KB | None | 0 0
  1. from requests import api
  2. import json
  3. import time
  4.  
  5. id_list = [27, 84, 271, 291, 337, 367, 403, 749, 757, 935, 1066, 1262, 1333, 1460, 1478, 1525, 2808, 19108, 19508, 20808, 21258, 28708, 35858, 40508, 41158, 47658, 53958, 54208, 55708, 56408, 58908, 60858, 61908, 67808, 71258, 73658, 79208, 191108, 191908, 254908, 266508, 347958, 392558, 394558, 408058, 423708, 440508, 585908, 598508, 605808, 666559, 710158, 716958, 721458, 721908, 723308, 729758, 740508, 751860, 772812, 774158, 787308, 793965, 875108, 914210, 927610, 969564, 973508, 980608, 995908, 1206958, 1274608, 1455709, 1458908, 1555661, 1613208, 1638758, 1662858, 1746810, 1784558, 1802358, 1807508, 1847469, 1864060, 2108708, 2173508, 2256258, 2257008, 2315358, 2438008, 2457608, 2460108, 2572958, 2645208, 2690558, 2716558, 2849309, 2873367, 3037258, 3114358, 3203158, 3245008, 3247358, 3323108, 3363358, 3456208, 3557908, 3626308, 3647758, 3709458, 3764658, 3782508, 4294758, 4620860, 4656513, 4955208, 5062258, 5068869, 5119458, 5431658, 5455208, 5553108, 5604258, 5730824, 6265808, 6271458, 6350958, 6478963, 6588760, 6596958, 6620558, 6626408, 7061508, 7248758, 7288708, 7351810, 7582462, 7625308, 7768458, 8165458, 8168758, 8250458, 8527308, 8528008, 8700958, 8713058, 8770808, 8788508, 8804658, 8836408, 8952758, 8956758, 9142058, 9207308, 9237108, 9244308, 9375858, 9841808, 9863758, 9930014, 9982658, 9991008, 10030908, 10032858, 10041808, 10181558, 10188609, 10287658, 10371758, 10470469, 10471258, 10508458, 10629011, 10743958, 10745408, 10954008, 11037058, 11157808, 11217608, 11226408, 11283858, 11338858, 11357608, 11454358, 11876658, 11933608, 12024108, 12080858, 12086508, 12241358, 12296708, 12542658, 12573458, 12634358, 12655158, 12780658, 12831858, 12862258, 12922308, 12943358, 12968672, 12970458, 13091258, 13228258, 13261008, 13676058, 13933260, 13957008, 13986158, 14103408, 14146811, 14146813, 14146819, 14154208, 14154308, 14156758, 14164508, 14186058, 14193608, 14195459, 14353358, 14398608, 14400058, 14583814, 14593508, 14632959, 14632968, 14654358, 14705909, 14705911, 14735058, 14824608, 14827958, 14895708, 14905508, 14951258, 15073214, 15106258, 15106808, 15108758, 15141609, 15212708, 15223158, 15309425, 15310166, 15396811, 15552508, 15597071, 15599210, 15599216, 15641958, 15719768, 15724958, 15820658, 15825459, 15825463, 15868608, 16028808, 16089908, 16096614, 16103411, 16292308, 16362958, 16377658, 16474908, 16504208, 16515808, 16521958, 16541358, 16600858, 16615208, 16637971, 16637972, 16637973, 16648508, 16649908, 16650608, 16653058, 16654108, 16654258, 16659058, 16659808, 16660058, 16665058, 16665458, 16667508, 16669008, 16669358, 16671458, 16672258, 16673808, 16674308, 16674958, 16738458, 16774110, 16786958, 16810259, 16915708, 16927108, 16998308, 17181258, 17212858, 17259858, 17271811, 17271814, 17356058, 17420508, 17421108, 17527608, 17554482, 17716758, 17802558, 17829058, 17883913, 17906408, 17925708, 17980458, 18158858, 18203170, 18210708, 18249608, 18260560, 18261408, 18314011, 18494008, 18543558, 18592258, 18597572, 18649808, 18762308, 18771708, 18934808, 18937208, 18987858, 19183108, 19194158, 19358108, 19361458, 19383608, 19386709, 19396808, 19514058, 19617608, 19627558, 19689758, 19716908, 19860958, 19921258, 19959158, 19965708, 19967108, 20128908, 20169508, 20175608, 20225008, 20260658, 20263058, 20314608, 20340108, 20370558, 20433658, 20558408, 20637908, 20685758, 20732558, 20791708, 20794208, 20809608, 20923608, 20943408, 20980908, 20987558, 21058808, 21093908, 21134808, 21134858, 21271108, 21311258, 21363209, 21378808, 21670908, 21833408, 21833558, 21842858, 21882308, 22006608, 22074408, 22111208, 22171609, 22267708, 22300408, 22418158, 22439660, 22477708, 22494808, 22651358, 22720258, 22725458, 22737558, 22741408, 22752108, 22783661, 22807058, 22820608, 22842158, 22905958, 22966208, 22972158, 23056308, 23118058, 23125158, 23234958, 23292208, 23313858, 23406808, 23437914, 23459158, 23475408, 23524908, 23577908, 23595358, 23616758, 23693058, 23724558, 23725508, 23740608, 23741408, 23746408, 23894658, 23956460, 23971608, 24060758, 24065413, 24082558, 24368858, 24441058, 24446908, 24508508, 24516008, 24538610, 24700408, 24748258, 24833758, 24836008, 24888058, 24891958, 24901008, 24956608, 24963758, 25041708, 25090458, 25098158, 25119308, 25129458, 25155908, 25170358, 25182058, 25195058, 25231058, 25242158, 25242808, 25293158, 25296608, 25309008, 25319158, 25323808, 25518708, 25545158, 25566258, 25624108, 25679008, 25843708, 25853458, 25909758, 25954108, 26190258, 26192558, 26255858, 26262508, 26295508, 26353608, 26365708, 26372808, 26422508, 26431208, 26484908, 26560208, 26587258, 26589008, 26653858, 26719408, 26722758, 26800708, 26853558, 26859658, 26865858, 27010808, 27033358, 27105758, 27150308, 27204108, 27229958, 27235758, 27321108, 27333008, 27381508, 27440908, 27457108, 27463308, 27523908, 27572808, 27681408, 27696158, 27699058, 27741508, 27791358, 27975558, 28068108, 28152258, 28198658, 28203208, 28251708, 28447408, 28456558, 28503458, 28505608, 28511508, 28598358, 28602508, 28730308, 28770208, 28794708, 28832458, 28879958, 28884358, 28887058, 29036758, 29060861, 29064408, 29140758, 29146708, 29190258, 29196008, 29298908, 29336658, 29401908, 29419408, 29462358, 29478708, 29483258, 29492108, 29520458, 29627408, 29699158, 29731208, 29737208, 29776459, 29795358, 29801058, 29802158, 29821858, 29862258, 29869408, 29874358, 29936408, 29939758, 29957108, 30003908, 30048108, 30098708, 30227908, 30240358, 30258158, 30279608, 30330158, 30374508, 30407758, 30419358, 30445058, 30467658, 30477608, 30637208, 30665461, 30676908, 30679558, 30680758, 30704408, 30746558, 30755508, 30888308, 30934758, 31000808, 31020358, 31159608, 31162709, 31210458, 31212708, 31216158, 31265508, 31311008, 31318258, 31328858, 31330408, 31333858, 31374458, 31408758, 31471958, 31528108, 31565958, 31590458, 31652508, 31697808, 31898008, 31944958, 31948408, 32003108, 32005808, 32041558, 32064658, 32081408, 32182558, 32215908, 32278808, 32285458, 32341608, 32362558, 32367308, 32372008, 32463808, 32474058, 32475758, 32486458, 32609608, 32625458, 32679008, 32700808, 32769908, 32858108, 32883058, 33014908, 33024358, 33031358, 33089508, 33100908, 33102108, 33112658, 33195058, 33207658, 33212458, 33213908, 33225558, 33422058, 33424858, 33431158, 33435108, 33437808, 33438358, 33449908, 33453408, 33504308, 33536108, 33549208, 33559658, 33573608, 33626208, 33629158, 33633008, 33687458, 33711158, 33801908, 33803108, 33805558, 33832558, 33897558, 33900908, 33901558, 33982308, 33990908, 34040958, 34046658, 34217508, 34219508, 34238008, 34278858, 34359958, 34374008, 34376758, 34401108, 34425608, 34437758, 34443158, 34444858, 34461708, 34490508, 34508858, 34509408, 34538908, 34585208, 34652208, 34679508, 34714508, 34734208, 34739758, 34862508, 34863308, 34997808, 35081158, 35096808, 35105659, 35114908, 35119508, 35158858, 35185958, 35215558, 35290258, 35299208, 35409308, 35528608, 35534108, 35535758, 35620258, 35622408, 35632608, 35776358, 35820458, 35821558, 35858908, 35903208, 36005308, 36014058, 36039158, 36159208, 36197158, 36268658, 36282358, 36287508, 36299508, 36441508, 36486558, 36548708, 36558858, 36622358, 36625458, 36632908, 36692458, 36716808, 36734908, 36772308, 36783458, 36835258, 36849308, 36856658, 36868058, 36977858, 36990908, 36992708, 37053358, 37058508, 37093358, 37108008, 37111708, 37131008, 37137008, 37160008, 37334458, 37339608, 37341108, 37359658, 37362458, 37468158, 37478608, 37549958, 37572758, 37584608, 37688808, 37704708, 37752258, 37809358, 37823508, 37878058, 37882308, 37887208, 37904308, 37929808, 37986358, 37991308, 37994258, 38059058, 38095558, 38105208, 38107708, 38137958, 38230008, 38250408, 38306208, 38484108, 38493008, 38507108, 38634858, 38640108, 38650958, 38656958, 38660358, 38680758, 38900858, 38910358, 38910408, 38929708, 38963608, 39030958, 39051258, 39069058, 39113658, 39140458, 39178008, 39201308, 39206008, 39258658, 39306308, 39389558, 39391258, 39468208, 39522258, 39619308, 39706958, 39888108, 39894558, 39910308, 39982108, 40040758, 40049758, 40052008, 40122458, 40423559, 40434158, 40466208, 40484808, 40547058, 40867708, 40943658, 41043708, 41364208]
  6.  
  7. def dictionarychecker(item, list):
  8. result = item
  9. for item in list:
  10. if item not in result:
  11. result = ''
  12. break
  13. elif len(item) > 0:
  14. result = result[item]
  15. else:
  16. result = ''
  17. break
  18. return result
  19.  
  20.  
  21. counter = 0
  22. fullString = ''
  23. hasMore = 'true'
  24. bigDict = {}
  25. bigList = []
  26. baseurl_engagements = 'https://api.hubapi.com/engagements/v1/engagements/paged'
  27. baseurl_contacts = 'https://api.hubapi.com/contacts/v1/lists/all/contacts/all?property=file_status'
  28. url_engagements = baseurl_engagements
  29. url_contacts = baseurl_contacts
  30. vid_list = []
  31. hasMore = True
  32. engagements_list = []
  33. notes_counter = 0
  34. tasks_counter = 0
  35. email_counter = 0
  36. call_counter = 0
  37. meeting_counter = 0
  38. with open('MVS_NOTES.csv', mode='a', newline='',encoding='utf-8') as MVS_NOTES,\
  39. open('MVS_TASKS.csv', mode='a', newline='', encoding='utf-8') as MVS_TASKS,\
  40. open('MVS_EMAIL.csv', mode='a', newline='', encoding='utf-8') as MVS_EMAIL,\
  41. open('MVS_CALL.csv', mode='a', newline='', encoding='utf-8') as MVS_CALL,\
  42. open('MVS_MEETING.csv', mode='a', newline='', encoding='utf-8') as MVS_MEETING:
  43. while hasMore == True:
  44. print("iteration count: " + str(counter))
  45. response = api.get(url_engagements,
  46. headers={
  47. 'Authorization': 'Bearer CNyjsb3KLRICAQMYsKgdIO-Z2AIoz5IMMhkAHW91hRgw2oefsyjt5wuO80wnhP6uWpLWOg8ACiJBAAAMgAMAOAAAAAVCGQAdb3WFeey5wAM7giesd5Snld52VCEQTDo',
  48. 'Content-Type': 'application/json'})
  49. d = json.loads(response.text)
  50. hasMore = d["hasMore"]
  51. offset = d["offset"]
  52. print(offset)
  53. url_engagements = baseurl_engagements + "?offset=" + str(offset)
  54. holder = d["results"].copy()
  55. for item in holder:
  56. associated_id = item['associations']['contactIds']
  57. associated_id_list = []
  58. for item2 in associated_id:
  59. associated_id_list.append(item2)
  60. for item3 in associated_id_list:
  61. if item3 in id_list:
  62. general_string = str(item['engagement']['id']) + ', ' + \
  63. str(item['engagement']['portalId']) + ', ' + \
  64. str(item['engagement']['active']) + ', ' + \
  65. str(item['engagement']['createdAt']) + ', ' + \
  66. str(item['engagement']['lastUpdated']) + ', ' + \
  67. str(item['engagement']['ownerId']) + ', ' + \
  68. str(item['engagement']['type']) + ', ' + \
  69. str(item['engagement']['timestamp']) + ', '
  70. engagement_type = item['engagement']['type']
  71. if engagement_type == "NOTE":
  72. break
  73. notes_counter += 1
  74. print("Notes:" + str(notes_counter))
  75. if len(item['attachments']) > 0:
  76. for id in item['attachments']:
  77. id_save = id['id']
  78. else:
  79. id_save = ''
  80. MVS_NOTES.write(general_string +
  81. str(id_save) + ', ' +
  82. "\"" + str(dictionarychecker(item, ['metadata', 'body'])) + "\"" +
  83. "\n")
  84. elif engagement_type == "TASK":
  85. updatedTime = item['engagement']['lastUpdated']
  86. if updatedTime > 1564031400000:
  87. tasks_counter += 1
  88. print("Tasks:" + str(tasks_counter))
  89. MVS_TASKS.write(general_string +
  90. "\"" + str(dictionarychecker(item, ['metadata', 'body'])) + "\"" + ', ' +
  91. "\"" + str(dictionarychecker(item, ['metadata', 'subject'])) + "\"" + ', ' +
  92. str(dictionarychecker(item, ['metadata', 'status'])) + ', ' +
  93. str(dictionarychecker(item, ['metadata', 'forObjectType'])) + ', ' +
  94. "\n")
  95. elif engagement_type == "EMAIL":
  96. break
  97. email_counter += 1
  98. print("Emails:" + str(email_counter))
  99. '''
  100. if len(item['metadata']['to']) > 0:
  101. for id in item['metadata']['to']:
  102. id_save = id['email']
  103. else:
  104. id_save = ''
  105. '''
  106. MVS_EMAIL.write(general_string +
  107. str(dictionarychecker(item, ['metadata', 'from', 'email'])) + ', ' +
  108. str(dictionarychecker(item, ['metadata', 'from', 'firstName'])) + ', ' +
  109. str(dictionarychecker(item, ['metadata', 'from', 'lastName'])) + ', ' +
  110. str(dictionarychecker(item, ['metadata', 'to', 'email'])) + ', ' +
  111. "\"" + str(item['metadata']['cc']) + "\"" + ', ' +
  112. "\"" + str(item['metadata']['bcc']) + "\"" + ', ' +
  113. "\"" + str(dictionarychecker(item, ['metadata', 'subject'])) + "\"" + ', ' +
  114. "\"" + str(dictionarychecker(item, ['metadata', 'html'])) + "\"" + ', ' +
  115. "\"" + str(dictionarychecker(item, ['metadata', 'text'])) + "\"" + ', ' +
  116. "\n")
  117. elif engagement_type == "CALL":
  118. break
  119. call_counter += 1
  120. print("Calls:" + str(call_counter))
  121. MVS_CALL.write(general_string +
  122. str(dictionarychecker(item, ['metadata', 'toNumber'])) + ', ' +
  123. str(dictionarychecker(item, ['metadata', 'FromNumber'])) + ', ' +
  124. str(dictionarychecker(item, ['metadata', 'status'])) + ', ' +
  125. str(dictionarychecker(item, ['metadata', 'externalId'])) + ', ' +
  126. str(dictionarychecker(item, ['metadata', 'durationMilliseconds'])) + ', ' +
  127. str(dictionarychecker(item, ['metadata', 'externalAccountId'])) + ', ' +
  128. str(dictionarychecker(item, ['metadata', 'recordingUrl'])) + ', ' +
  129. str(dictionarychecker(item, ['metadata', 'body'])) + ', ' +
  130. str(dictionarychecker(item, ['metadata', 'disposition'])) + ', ' +
  131. "\n")
  132. elif engagement_type == "MEETING":
  133. break
  134. meeting_counter += 1
  135. print("Meetings:" + str(meeting_counter))
  136. MVS_MEETING.write(general_string +
  137. "\"" + str(dictionarychecker(item, ['metadata', 'body'])) + "\"" + ', ' +
  138. str(dictionarychecker(item, ['metadata', 'startTime'])) + ', ' +
  139. str(dictionarychecker(item, ['metadata', 'endTime'])) + ', ' +
  140. str(dictionarychecker(item, ['metadata', 'title'])) + ', ' +
  141. "\n")
  142. counter = counter + 1
  143. MVS_NOTES.close()
  144. MVS_TASKS.close()
  145. MVS_EMAIL.close()
  146. MVS_CALL.close()
  147. MVS_MEETING.close()
  148. print("COMPLETE")
  149.  
  150. #with open('test.json', 'w') as json_file:
  151. # json.dump(bigDict, json_file)
  152.  
  153. '''
  154.  
  155. while hasMore == True:
  156. print("iteration count: " + str(counter))
  157. print(url_contacts)
  158. response = api.get(url_contacts,
  159. headers={
  160. 'Authorization': 'Bearer CLHS9uDBLRICAQMYsKgdIO-Z2AIoz5IMMhkAdKEUDbGe2w6FApLav-spJfDYekOQB-iuOg8ACiJBAAAMgAMAOAAAAAVCGQB0oRQNCyTdTq4C6bWLBJZPVROhdoGU3-4',
  161. 'Content-Type': 'application/json'})
  162. #d = response.text.replace("\'", "\"")
  163. d = json.loads(response.text)
  164. print(d)
  165. hasMore = d["has-more"]
  166. print(hasMore)
  167. offset = d["vid-offset"]
  168. print(offset)
  169. url_contacts = baseurl_contacts + "&vidOffset=" + str(offset)
  170. holder = d["contacts"].copy()
  171. print(len(holder))
  172. for item in holder:
  173. bigList.append(item)
  174. bigDict[str(counter)] = d["contacts"].copy()
  175. counter = counter + 1
  176. for item in bigList:
  177. if 'file_status' in item["properties"]:
  178. file_status = item["properties"]['file_status']['value']
  179. print(file_status)
  180. if file_status == "Active":
  181. vid_list.append(item["vid"])
  182. print(vid_list)
  183. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement