This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wonderApi.py
65 lines (49 loc) · 2.12 KB
/
wonderApi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import datetime
import re
from robobrowser import RoboBrowser
class WonderApi:
global WWVillage_Name
WWVillage_Name = "WW Village"
def __init__(self, user, pasw, linkName):
self.link = 'http://www.travianwonder.com/%s' % linkName
self.browser = RoboBrowser(history=True, parser='html.parser')
self.browser.open(self.link)
self.loggin(user, pasw)
def loggin(self, _user, _pasw):
self.logActions("Logging as '%s'" % _user)
self.browser.open(self.link + "/admin")
form = self.browser.get_form(id='loginForm')
# print(form)
form['user'] = _user
form['password'] = _pasw
# self.browser.session.headers['Referer'] = self.link
self.browser.submit_form(form)
self.logActions("Logged in successfully!")
def updateResources(self, source):
self.logActions('Prepare update resources')
resourceLink = self.link + "/resources"
self.browser.open(resourceLink)
try:
form = self.browser.get_form(id='resourcesForm')
form['htmlCode'].value = str(source)
# form['htmlCodeFile'].value = open(filename, 'rb')
# print(form)
self.browser.submit_form(form)
self.logActions("Resource update request has been send!")
return True
except Exception as e:
print("Something went wrong when try update resources")
print(str(e))
return False
def updateResourcesReq(self):
self.logActions('Prepare update resources')
filename = "C:\\Users\\Root\\AppData\\Local\\Temp\\travian.html"
resourceLink = self.link + "/resources"
try:
self.browser.open(resourceLink, method='post', data={'htmlCode': '',
'htmlCodeFile': open(filename, 'rb'),
'submitBtn': ' TALLENNA '})
except Exception as e:
print(str(e))
def logActions(self, action):
print('[%s | wonderAPI] %s' % (datetime.datetime.now(), action))