Created
September 14, 2019 17:16
-
-
Save A-w-K/ca407aa070f62ee46f8af4e20d435766 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from selenium import webdriver | |
from multiprocessing import Process, Lock, Array, Value | |
from multiprocessing.dummy import Pool as ThreadPool | |
maxX = 150 | |
maxY = 150 | |
steps = [8, 23, 38, 53, 68, 83, 98, 113, 128, 143] | |
arr = Array('i', range(maxX * maxY)) | |
SESSION_ID = 'DEINE SESSION ID HIER' | |
options = webdriver.ChromeOptions() | |
options.add_argument('headless') | |
driver = webdriver.Chrome(options=options) | |
driver.get("http://www.demonlords.de") | |
cookie = {'name': 'session_id', 'value': SESSION_ID} | |
driver.add_cookie(cookie) | |
urlsReal = ["http://www.demonlords.de/main.php?location=karte&x=8y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=83", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=98", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=113", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=128", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=143", | |
"http://www.demonlords.de/main.php?location=karte&x=23y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=23y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=23y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=23y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=23y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=23y=83", | |
"http://www.demonlords.de/main.php?location=karte&x=23y=98", | |
"http://www.demonlords.de/main.php?location=karte&x=23y=113", | |
"http://www.demonlords.de/main.php?location=karte&x=23y=128", | |
"http://www.demonlords.de/main.php?location=karte&x=23y=143", | |
"http://www.demonlords.de/main.php?location=karte&x=38y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=38y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=38y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=38y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=38y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=38y=83", | |
"http://www.demonlords.de/main.php?location=karte&x=38y=98", | |
"http://www.demonlords.de/main.php?location=karte&x=38y=113", | |
"http://www.demonlords.de/main.php?location=karte&x=38y=128", | |
"http://www.demonlords.de/main.php?location=karte&x=38y=143", | |
"http://www.demonlords.de/main.php?location=karte&x=53y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=53y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=53y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=53y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=53y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=53y=83", | |
"http://www.demonlords.de/main.php?location=karte&x=53y=98", | |
"http://www.demonlords.de/main.php?location=karte&x=53y=113", | |
"http://www.demonlords.de/main.php?location=karte&x=53y=128", | |
"http://www.demonlords.de/main.php?location=karte&x=53y=143", | |
"http://www.demonlords.de/main.php?location=karte&x=68y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=68y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=68y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=68y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=68y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=68y=83", | |
"http://www.demonlords.de/main.php?location=karte&x=68y=98", | |
"http://www.demonlords.de/main.php?location=karte&x=68y=113", | |
"http://www.demonlords.de/main.php?location=karte&x=68y=128", | |
"http://www.demonlords.de/main.php?location=karte&x=68y=143", | |
"http://www.demonlords.de/main.php?location=karte&x=83y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=83y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=83y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=83y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=83y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=83y=83", | |
"http://www.demonlords.de/main.php?location=karte&x=83y=98", | |
"http://www.demonlords.de/main.php?location=karte&x=83y=113", | |
"http://www.demonlords.de/main.php?location=karte&x=83y=128", | |
"http://www.demonlords.de/main.php?location=karte&x=83y=143", | |
"http://www.demonlords.de/main.php?location=karte&x=98y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=98y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=98y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=98y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=98y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=98y=83", | |
"http://www.demonlords.de/main.php?location=karte&x=98y=98", | |
"http://www.demonlords.de/main.php?location=karte&x=98y=113", | |
"http://www.demonlords.de/main.php?location=karte&x=98y=128", | |
"http://www.demonlords.de/main.php?location=karte&x=98y=143", | |
"http://www.demonlords.de/main.php?location=karte&x=113y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=113y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=113y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=113y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=113y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=113y=83", | |
"http://www.demonlords.de/main.php?location=karte&x=113y=98", | |
"http://www.demonlords.de/main.php?location=karte&x=113y=113", | |
"http://www.demonlords.de/main.php?location=karte&x=113y=128", | |
"http://www.demonlords.de/main.php?location=karte&x=113y=143", | |
"http://www.demonlords.de/main.php?location=karte&x=128y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=128y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=128y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=128y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=128y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=128y=83", | |
"http://www.demonlords.de/main.php?location=karte&x=128y=98", | |
"http://www.demonlords.de/main.php?location=karte&x=128y=113", | |
"http://www.demonlords.de/main.php?location=karte&x=128y=128", | |
"http://www.demonlords.de/main.php?location=karte&x=128y=143", | |
"http://www.demonlords.de/main.php?location=karte&x=143y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=143y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=143y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=143y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=143y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=143y=83", | |
"http://www.demonlords.de/main.php?location=karte&x=143y=98", | |
"http://www.demonlords.de/main.php?location=karte&x=143y=113", | |
"http://www.demonlords.de/main.php?location=karte&x=143y=128", | |
"http://www.demonlords.de/main.php?location=karte&x=143y=143"] | |
urlsTest = ["http://www.demonlords.de/main.php?location=karte&x=8y=8", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=23", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=38", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=53", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=68", | |
"http://www.demonlords.de/main.php?location=karte&x=8y=83"] | |
urlSingle = "http://www.demonlords.de/main.php?location=karte&x=8y=8" | |
def parse(u): | |
print(str(urlsReal.index(u)) + ':' + u) | |
driver.get(u) | |
map_data = driver.execute_script("return window.mapData") | |
if map_data: | |
for key, value in map_data.items(): | |
x = value['x'] | |
y = value['y'] | |
mon_data = value['mondata'] | |
if mon_data: | |
gold = mon_data[len(mon_data) - 1] | |
arr[(y - 1) * maxY + (x-1)] = gold # maybe need to use (coord - 1) | |
def dl(urls, method): | |
pool = ThreadPool(1) | |
results = pool.map(method, urls) | |
pool.close() | |
pool.join() | |
return results | |
def get_best_fields(fields): | |
copy = fields[:] | |
sorted_fields = sorted(copy, reverse=True) | |
top_fields = [] | |
for i in range(10): | |
index = copy.index(sorted_fields[i]) | |
x = index % maxX + 1 | |
y = math.floor(index/maxX) + 1 | |
top_fields.append({ | |
'x': x, | |
'y': y, | |
'gold': sorted_fields[i], | |
'link': "http://www.demonlords.de/main.php?location=karte&x=%d&y=%d" % (x, y) | |
}) | |
return top_fields | |
dl(urlsReal, parse) | |
driver.quit() | |
print(get_best_fields(arr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment