app.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. """Test module"""
  2. import sys
  3. import json
  4. from rival_regions_wrapper import Client
  5. def read_credentials(filename):
  6. """Read credentials from filename"""
  7. with open(filename) as credential_file:
  8. return json.load(credential_file)
  9. def login(credentials=None):
  10. """Main method"""
  11. if credentials is None:
  12. credentials = {}
  13. credentials['username'] = input("Username: ")
  14. credentials['password'] = input("Password: ")
  15. credentials['method'] = input("Login Method: ")
  16. client = Client(show_window=True)
  17. client.login(credentials)
  18. print(client.var_c)
  19. action_dict = {
  20. 'market': market,
  21. 'oil_market': oil_market,
  22. 'article': article,
  23. 'get': get,
  24. 'gold_exploration': gold_exploration,
  25. 'vote_law': vote_law,
  26. }
  27. print(action_dict.keys())
  28. while True:
  29. action = input("Action: ")
  30. if action in action_dict:
  31. action_dict[action](client)
  32. else:
  33. print('action not found')
  34. def market(client):
  35. """Get all market prices"""
  36. market_info = client.get_all_market_info()
  37. for i in market_info:
  38. print("")
  39. print(i.upper())
  40. print("#"*len(i))
  41. for j in market_info[i]:
  42. print(j.upper() + ':' + market_info[i][j])
  43. def oil_market(client):
  44. """Get oil market price"""
  45. print(client.market_info('oil'))
  46. def article(client):
  47. """Create article"""
  48. client.create_article('Nothing to see here', '')
  49. def get(client):
  50. """Send get request from client"""
  51. path = input('Path: ')
  52. result = client.get(path)
  53. print(result)
  54. def gold_exploration(client):
  55. """Create gold exploration law"""
  56. resoure = 0
  57. data = {
  58. 'tmp_gov': resoure
  59. }
  60. result = client.post('parliament/donew/42/{}/0'.format(resoure), data)
  61. print(result)
  62. def vote_law(client):
  63. """Vote for a law"""
  64. # p400220003260451563564814
  65. # p4002 2000326045 1563564814
  66. # 'parliament/votelaw/4002/2000326045/1563564814/pro'
  67. # 'parliament/votelaw/4002/2000326045/1563565114/pro'
  68. region_id = 4002
  69. player_id = 2000326045
  70. law_id = 1563565114
  71. result = client.post('parliament/votelaw/{}/{}/{}/pro'.format(
  72. region_id,
  73. player_id,
  74. law_id
  75. ), {})
  76. print(result)
  77. if __name__ == "__main__":
  78. if len(sys.argv) >= 2:
  79. CREDENTIALS = read_credentials(sys.argv[1])
  80. login(CREDENTIALS)
  81. else:
  82. login()