Last active
July 7, 2017 19:26
-
-
Save KhanMaytok/b23df714e43423e4571073c58f3ce83e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 requests | |
import sqlite3 as lite | |
import xml.etree.ElementTree as ET | |
r = requests.get("https://s130-es.ogame.gameforge.com/api/highscore.xml?category=1&type=0") | |
score = r.content | |
root = ET.fromstring(score) | |
all_data = [] | |
timestamp = root.attrib['timestamp'] | |
con = lite.connect('ogame.db') | |
for child in root: | |
at = child.attrib | |
position = at.get('position') | |
player_id = at.get('id') | |
score = at.get('score') | |
params = (position, player_id, score, timestamp) | |
all_data.append(params) | |
with con: | |
cur = con.cursor() | |
cur.execute("DELETE FROM Highscore") | |
cur.executemany("INSERT INTO Highscore(position, player_id, score, updated_at) VALUES(?,?,?,?)", all_data) | |
if con: | |
con.close() |
This file contains hidden or 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 argparse | |
import requests | |
import sqlite3 as lite | |
import xml.etree.ElementTree as ET | |
from random import shuffle | |
parser2 = argparse.ArgumentParser(description='Auttomated attack to targets.') | |
parser2.add_argument("-b", "--begin", dest="inicio", | |
default=1, | |
type=int, | |
help='Begin to captuer') | |
parser2.add_argument("-e", "--end", dest="final", | |
default=420, | |
type=int, | |
help='End of capture') | |
parser2.add_argument("-p", "--position", dest="position", | |
default=1400, | |
type=int, | |
help='Max position to scan') | |
args2 = parser2.parse_args() | |
inicio = args2.inicio | |
final = args2.final | |
position = args2.position | |
r = requests.get("https://s130-es.ogame.gameforge.com/api/universe.xml") | |
p = requests.get("https://s130-es.ogame.gameforge.com/api/players.xml") | |
uni = r.content | |
players = p.content | |
root_uni = ET.fromstring(uni) | |
root_players = ET.fromstring(players) | |
con = lite.connect('ogame.db') | |
# Empty the database | |
cur = con.cursor() | |
cur.execute("DELETE FROM Universe") | |
cur.execute("DELETE FROM Player") | |
all_data = [] | |
# UPDATE THE PLANETS | |
for child in root_uni: | |
at = child.attrib | |
id_player = at['id'] | |
player = at['player'] | |
coords = at['coords'] | |
galaxy = coords.split(':')[0] | |
system = coords.split(':')[1] | |
planet = coords.split(':')[2] | |
params = (id_player, player, coords, galaxy, system, planet) | |
all_data.append(params) | |
with con: | |
cur = con.cursor() | |
cur.executemany("INSERT INTO Universe(id, player, coords, galaxy, system, planet) VALUES(?,?,?,?,?,?)", all_data) | |
print('All planets are keep') | |
all_data = [] | |
for child in root_players: | |
at = child.attrib | |
id_player = at['id'] | |
status = at.get('status') | |
name = at['name'] | |
params = (id_player, name, status) | |
all_data.append(params) | |
with con: | |
cur = con.cursor() | |
cur.executemany("INSERT INTO Player(id, name, status) VALUES(?,?,?)", all_data) | |
# UPDATE THE PLAYERS | |
minor_inactive = '%i' | |
major_inactive = '%I%' | |
vacations = '%v%' | |
cur.execute("""SELECT Universe.coords | |
FROM | |
Player, | |
Universe, | |
Highscore | |
WHERE | |
Universe.player = Player.id | |
AND Highscore.player_id = Player.id | |
and Highscore.position <= ? | |
AND ( | |
Player.status LIKE ? | |
OR Player.status LIKE ? | |
)AND Player.status NOT LIKE ? | |
AND Universe.system >= ? AND Universe.system <= ?""", | |
(position, minor_inactive, major_inactive, vacations, inicio, final)) | |
data = cur.fetchall() | |
shuffle(data) | |
print('El numero de inactivos es: {}'.format(len(data))) | |
with open('inactivos.txt', 'w') as f: | |
for row in data: | |
f.write("%s " % str(row[0])) | |
if con: | |
con.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment