Advertisement
Guest User

Untitled

a guest
Jul 11th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.03 KB | None | 0 0
  1. import requests
  2. import base64
  3. import json
  4. import os
  5. import time
  6. import string
  7. import random
  8. import names
  9.  
  10. egelauth="Basic XXXX"
  11. #egelcompanyid="XXXXX" #dev
  12. #egelcompanyid="XXXX"
  13. egelaccountid="XXX" #stable
  14. i=0
  15. password="XXXX"
  16. urlbasis="http://dev.alpha-trader.com/"
  17. partnerid="XXXXX" #stable
  18. #partnerid="XXXXX"
  19. #partnerid="XXXXX"#dev
  20. headeregel={
  21. 'authorization': egelauth,
  22. 'x-authorization': partnerid,
  23. 'cache-control': "no-cache",
  24. }
  25. auth=""
  26.  
  27. def createuser(username):
  28. print("createuser")
  29. print("\n")
  30. url = urlbasis+"user/register"
  31. mail=username+"@gmx.de"
  32. companyname="comp"+username
  33. querystring = {"username":username,"emailAddress":mail,"password":password}
  34. headers = {
  35. 'x-authorization': partnerid,
  36. 'cache-control': "no-cache",
  37. }
  38. response = requests.request("POST", url, headers=headers, params=querystring)
  39. print(response.text)
  40. print("\n")
  41.  
  42. def createcompany(companyname, username):
  43. print("createcompany")
  44. print("\n")
  45. url = urlbasis+"api/companies/"
  46. querystring = {"name":companyname,"cashDeposit":"50000"}
  47. headers = {
  48. 'authorization': auth,
  49. 'x-authorization': partnerid,
  50. 'cache-control': "no-cache",
  51. }
  52. response = requests.request("POST", url, headers=headers, params=querystring)
  53. print(response.text)
  54. print("\n")
  55.  
  56. def getcompanyidbyuser(username):
  57. print("getcompanyidbyuser")
  58. print("\n")
  59. url = urlbasis+"api/companies/ceo/username/"+username
  60. response = requests.request("GET", url, headers=headeregel)
  61. parsed_json = json.loads(response.text)
  62. companyid=parsed_json[0]['id']
  63. return companyid
  64.  
  65. def employegelasceo(companyid):
  66. print("employegelasceo")
  67. print("\n")
  68. url = urlbasis+"api/polls/employceo"
  69. querystring = {"companyId":companyid,"dailyWage":"150"}
  70. response = requests.request("POST", url, headers=headeregel, params=querystring)
  71. print(response.text)
  72. print("\n")
  73. url = urlbasis+"api/polls/"
  74. headers = {
  75. 'authorization': auth,
  76. 'x-authorization': partnerid,
  77. 'cache-control': "no-cache",
  78. }
  79.  
  80. response = requests.request("GET", url, headers=headers)
  81. parsed_json = json.loads(response.text)
  82. pollid=parsed_json[0]['id']
  83. print(pollid)
  84.  
  85. url = urlbasis+"api/polls/"+pollid
  86.  
  87. querystring = {"voices":"50000","votingType":"YES"}
  88. headers = {
  89. 'authorization': auth,
  90. 'x-authorization': partnerid,
  91. 'cache-control': "no-cache",
  92. }
  93. response = requests.request("POST", url, headers=headers, params=querystring)
  94. print(response.text)
  95. print("\n")
  96. #print(response.text)
  97.  
  98. url = urlbasis+"api/polls/execute/"+pollid
  99. response = requests.request("POST", url, headers=headeregel)
  100.  
  101. def getsecurityidentifier(companyname):
  102. print("getsecurityidentifier")
  103. print("\n")
  104. url = urlbasis+"api/search/companies/"+companyname
  105.  
  106. headers = {
  107. 'authorization': egelauth,
  108. 'x-authorization': partnerid,
  109. 'cache-control': "no-cache",
  110. }
  111. response = requests.request("GET", url, headers=headers)
  112. print(response.text)
  113. print("\n")
  114. parsed_json = json.loads(response.text)
  115. securityidentifier=parsed_json[0]['securityIdentifier']
  116. return securityidentifier
  117.  
  118. def getsecurityaccount(companyname):
  119. print("getsecurityaccount")
  120. print("\n")
  121. url = urlbasis+"api/search/companies/"+companyname
  122.  
  123. headers = {
  124. 'authorization': egelauth,
  125. 'x-authorization': partnerid,
  126. 'cache-control': "no-cache",
  127. }
  128. response = requests.request("GET", url, headers=headers)
  129. print(response.text)
  130. print("\n")
  131. parsed_json = json.loads(response.text)
  132. securityaccount=parsed_json[0]['securitiesAccountId']
  133. return securityaccount
  134.  
  135. def getcompanyidbyname(companyname):
  136. print("getcompanyidbyname")
  137. print("\n")
  138. url = urlbasis+"api/search/companies/"+companyname
  139.  
  140. headers = {
  141. 'authorization': egelauth,
  142. 'x-authorization': partnerid,
  143. 'cache-control': "no-cache",
  144. }
  145. response = requests.request("GET", url, headers=headers)
  146. print(response.text)
  147. print("\n")
  148. parsed_json = json.loads(response.text)
  149. securityaccount=parsed_json[0]['id']
  150. return securityaccount
  151.  
  152. def otcordersell(company1, company2):
  153. print("otcordersell")
  154. print("\n")
  155. url = urlbasis+"api/securityorders/"
  156. querystring = {"owner":getsecurityaccount(company1),"securityIdentifier":getsecurityidentifier(company1),"action":"SELL","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":getsecurityaccount(company2)}
  157. headers = {
  158. 'authorization': egelauth,
  159. 'x-authorization': partnerid,
  160. 'cache-control': "no-cache",
  161.  
  162. }
  163. response = requests.request("POST", url, headers=headers, params=querystring)
  164. print(response.text)
  165. print("\n")
  166. querystring = {"owner":getsecurityaccount(company2),"securityIdentifier":getsecurityidentifier(company1),"action":"BUY","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":getsecurityaccount(company1)}
  167. response = requests.request("POST", url, headers=headers, params=querystring)
  168. print(response.text)
  169. print("\n")
  170.  
  171. def intitiateliquidationpoll(company):
  172. print("initiateliquidationpoll")
  173. print("\n")
  174. url = urlbasis+"api/polls/liquidation"
  175. querystring = {"companyId":getcompanyidbyname(company)}
  176. headers = {
  177. 'authorization': egelauth,
  178. 'x-authorization': partnerid,
  179. 'cache-control': "no-cache",
  180. }
  181. response = requests.request("POST", url, headers=headers, params=querystring)
  182. print(response.text)
  183. print("\n")
  184.  
  185. #def acceptliquidationpoll(company)
  186. def sellowncompany(company, auth):
  187. print("sellowncompany")
  188. print("\n")
  189. url = urlbasis+"api/securityorders/"
  190. querystring = {"owner":getsecurityaccount(company),"securityIdentifier":getsecurityidentifier(company),"action":"SELL","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":""}
  191. headers = {
  192. 'authorization': auth,
  193. 'x-authorization': partnerid,
  194. 'cache-control': "no-cache",
  195.  
  196. }
  197. response = requests.request("POST", url, headers=headers, params=querystring)
  198. print(response.text)
  199. print("\n")
  200.  
  201. def getlastpoll():
  202. print("getlastpoll")
  203. print("\n")
  204. url = urlbasis+"api/initiatedpolls/"
  205. response = requests.request("GET", url, headers=headeregel)
  206.  
  207. parsed_json = json.loads(response.text)
  208. #print(parsed_json.lentgh())
  209. pollid=parsed_json[-1]['id']
  210. return pollid
  211.  
  212. def votepoll (pollid):
  213. print("votepoll")
  214. print("\n")
  215. url = urlbasis+"api/polls/"+pollid
  216. querystring = {"voices":"50000","votingType":"YES"}
  217. response = requests.request("POST", url, headers=headeregel, params=querystring)
  218.  
  219.  
  220. def expoll (pollid):
  221. print("createuser")
  222. print("\n")
  223. url = urlbasis+"api/polls/execute/"+pollid
  224. response = requests.request("POST", url, headers=headeregel)
  225.  
  226. def id_generator(size=60, chars=string.ascii_uppercase + string.digits):
  227. return ''.join(random.choice(chars) for _ in range(size))
  228.  
  229. def randomName(capitalize):
  230.  
  231. bits=[]
  232. vowels="aeiou"
  233. letters="abcdefghijklmnopqrstuvwxyz"
  234. for ch in letters:
  235. for v in vowels:
  236. bits.append(ch+v)
  237. bits.remove("fu")
  238. bits.remove("hi")
  239. bits.remove("cu")
  240. bits.remove("co")
  241. bits.remove("mo")
  242. word=""
  243. rnd=len(bits)-1
  244. numOfBits=random.randint(2,3)
  245. for i in range(0,numOfBits):
  246. word=word+bits[random.randint(1,rnd)]
  247. word=word+letters[random.randrange(0,25)]
  248. if (capitalize==True):
  249. word=word.capitalize()
  250. return word
  251.  
  252.  
  253. i=1
  254. while i<100:
  255. username="ZZZ"+id_generator()
  256. #username=names.get_first_name()
  257. ag=username
  258. auth=username+":"+password
  259. auth= base64.encodestring(auth)
  260. auth="Basic "+auth
  261. auth=auth.replace('\n', '')
  262. createuser(username)
  263. createcompany(ag, username)
  264. print(username)
  265. #employegelasceo(getcompanyidbyuser(username))
  266. otcordersell(ag, "Bender")
  267. #time.sleep(2)
  268. #intitiateliquidationpoll(ag)
  269. #lastpoll=getlastpoll()
  270. #votepoll(lastpoll)
  271. #expoll(getlastpoll())
  272. i=i+1
  273. print(username)
  274.  
  275.  
  276.  
  277.  
  278. #employegelasceo(getcompanyidbyuser(username))
  279. #auth=egelauth
  280. #comp="Bis%20zum%20naechsten%20reset"
  281. #otcordersell(comp, "Bender")
  282. #intitiateliquidationpoll(comp)
  283. #getlastpoll()
  284. #print(getcompanyidbyname(comp))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement