Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.88 KB | None | 0 0
  1. from requests import api
  2. import json
  3.  
  4. 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]
  5.  
  6. def dictionarychecker(item, list):
  7. result = item
  8. for item in list:
  9. if item not in result:
  10. result = ''
  11. break
  12. elif len(item) > 0:
  13. result = result[item]
  14. else:
  15. result = ''
  16. break
  17. return result
  18.  
  19.  
  20. counter = 0
  21. fullString = ''
  22. hasMore = 'true'
  23. bigDict = {}
  24. bigList = []
  25. baseurl_engagements = 'https://api.hubapi.com/engagements/v1/engagements/paged'
  26. baseurl_contacts = 'https://api.hubapi.com/contacts/v1/lists/all/contacts/all?property=file_status'
  27. url_engagements = baseurl_engagements
  28. url_contacts = baseurl_contacts
  29. vid_list = []
  30. hasMore = True
  31. engagements_list = []
  32. with open('MVS_NOTES.csv', mode='a', newline='',encoding='utf-8') as MVS_NOTES,\
  33. open('MVS_TASKS.csv', mode='a', newline='', encoding='utf-8') as MVS_TASKS,\
  34. open('MVS_EMAIL.csv', mode='a', newline='', encoding='utf-8') as MVS_EMAIL,\
  35. open('MVS_CALL.csv', mode='a', newline='', encoding='utf-8') as MVS_CALL,\
  36. open('MVS_MEETING.csv', mode='a', newline='', encoding='utf-8') as MVS_MEETING:
  37. while counter < 20:
  38. print("iteration count: " + str(counter))
  39. response = api.get(url_engagements,
  40. headers={
  41. 'Authorization': 'Bearer CIGgoevBLRICAQMYsKgdIO-Z2AIoz5IMMhkAk8itC1-JzbULXhM4lISMxHfJ3PtmW4oMOg8ACiJBAAAMgAMAOAAAAAVCGQCTyK0L0QYVtPRw3_EdKHBD-zvGhTK5e6Q',
  42. 'Content-Type': 'application/json'})
  43. d = json.loads(response.text)
  44. hasMore = d["hasMore"]
  45. offset = d["offset"]
  46. print(offset)
  47. url_engagements = baseurl_engagements + "?offset=" + str(offset)
  48. holder = d["results"].copy()
  49. for item in holder:
  50. associated_id = item['associations']['contactIds']
  51. associated_id_list = []
  52. for item2 in associated_id:
  53. associated_id_list.append(item2)
  54. for item3 in associated_id_list:
  55. if item3 in id_list:
  56. general_string = str(item['engagement']['id']) + ', ' + \
  57. str(item['engagement']['portalId']) + ', ' + \
  58. str(item['engagement']['active']) + ', ' + \
  59. str(item['engagement']['createdAt']) + ', ' + \
  60. str(item['engagement']['lastUpdated']) + ', ' + \
  61. str(item['engagement']['ownerId']) + ', ' + \
  62. str(item['engagement']['type']) + ', ' + \
  63. str(item['engagement']['timestamp']) + ', '
  64. engagement_type = item['engagement']['type']
  65. print(engagement_type)
  66. if engagement_type == "NOTE":
  67. if len(item['attachments']) > 0:
  68. for id in item['attachments']:
  69. id_save = id['id']
  70. else:
  71. id_save = ''
  72. MVS_NOTES.write(general_string +
  73. str(id_save) + ', ' +
  74. str(item['metadata']['body']) +
  75. "\n")
  76. elif engagement_type == "TASK":
  77. MVS_TASKS.write(general_string +
  78. str(item['metadata']['body']) + ', ' +
  79. str(dictionarychecker(item, ['metadata', 'subject'])) + ', ' +
  80. str(item['metadata']['status']) + ', ' +
  81. str(item['metadata']['forObjectType']) +
  82. "\n")
  83. elif engagement_type == "EMAIL":
  84. if len(item['metadata']['to']) > 0:
  85. for id in item['metadata']['to']:
  86. id_save = id['email']
  87. else:
  88. id_save = ''
  89. MVS_EMAIL.write(general_string +
  90. str(dictionarychecker(item, ['metadata', 'from', 'email'])) + ', ' +
  91. str(dictionarychecker(item, ['metadata', 'from', 'firstName'])) + ', ' +
  92. str(dictionarychecker(item, ['metadata', 'from', 'lastName'])) + ', ' +
  93. str(id_save) + ', ' +
  94. str(item['metadata']['cc']) + ', ' +
  95. str(item['metadata']['bcc']) + ', ' +
  96. "\"" + str(dictionarychecker(item, ['metadata', 'subject'])) + "\"" + ', ' +
  97. str(item['metadata']['html']) + ', ' +
  98. str(dictionarychecker(item, ['metadata', 'text'])) + ', ' +
  99. "\n")
  100. elif engagement_type == "CALL":
  101. MVS_CALL.write(general_string +
  102. str(dictionarychecker(item, ['metadata', 'toNumber'])) + ', ' +
  103. str(dictionarychecker(item, ['metadata', 'FromNumber'])) + ', ' +
  104. str(dictionarychecker(item, ['metadata', 'status'])) + ', ' +
  105. str(dictionarychecker(item, ['metadata', 'externalId'])) + ', ' +
  106. str(item['metadata']['durationMilliseconds']) + ', ' +
  107. str(dictionarychecker(item, ['metadata', 'externalAccountId'])) + ', ' +
  108. str(dictionarychecker(item, ['metadata', 'recordingUrl'])) + ', ' +
  109. str(item['metadata']['body']) + ', ' +
  110. str(dictionarychecker(item, ['metadata', 'disposition'])) + ', ' +
  111. "\n")
  112. elif engagement_type == "MEETING":
  113. MVS_MEETING.write(general_string +
  114. str(item['metadata']['body']) + ', ' +
  115. str(item['metadata']['startTime']) + ', ' +
  116. str(item['metadata']['endTime']) + ', ' +
  117. str(item['metadata']['title']) +
  118. "\n")
  119. counter = counter + 1
  120. MVS_NOTES.close()
  121. MVS_TASKS.close()
  122. MVS_EMAIL.close()
  123. MVS_CALL.close()
  124. MVS_MEETING.close()
  125. print("COMPLETE")
  126.  
  127. #with open('test.json', 'w') as json_file:
  128. # json.dump(bigDict, json_file)
  129.  
  130. '''
  131.  
  132. while hasMore == True:
  133. print("iteration count: " + str(counter))
  134. print(url_contacts)
  135. response = api.get(url_contacts,
  136. headers={
  137. 'Authorization': 'Bearer CLHS9uDBLRICAQMYsKgdIO-Z2AIoz5IMMhkAdKEUDbGe2w6FApLav-spJfDYekOQB-iuOg8ACiJBAAAMgAMAOAAAAAVCGQB0oRQNCyTdTq4C6bWLBJZPVROhdoGU3-4',
  138. 'Content-Type': 'application/json'})
  139. #d = response.text.replace("\'", "\"")
  140. d = json.loads(response.text)
  141. print(d)
  142. hasMore = d["has-more"]
  143. print(hasMore)
  144. offset = d["vid-offset"]
  145. print(offset)
  146. url_contacts = baseurl_contacts + "&vidOffset=" + str(offset)
  147. holder = d["contacts"].copy()
  148. print(len(holder))
  149. for item in holder:
  150. bigList.append(item)
  151. bigDict[str(counter)] = d["contacts"].copy()
  152. counter = counter + 1
  153. for item in bigList:
  154. if 'file_status' in item["properties"]:
  155. file_status = item["properties"]['file_status']['value']
  156. print(file_status)
  157. if file_status == "Active":
  158. vid_list.append(item["vid"])
  159. print(vid_list)
  160. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement