ComunioPy
Advanced tools
+39
-64
@@ -7,6 +7,4 @@ #!/usr/bin/env python | ||
| import os | ||
| from pyvirtualdisplay import Display | ||
| import re | ||
| import requests | ||
| from selenium import webdriver | ||
| import sys | ||
@@ -32,2 +30,3 @@ import time | ||
| self.session = requests.session() | ||
| self.login() | ||
@@ -40,10 +39,10 @@ def login(self): | ||
| req = self.session.post('http://'+self.domain+'/login.phtml',headers=headers,data=payload).content | ||
| #soup = BeautifulSoup(req) | ||
| if 'puntos en proceso' in req: | ||
| if 'puntos en proceso' in req or 'points in process' in req: | ||
| print 'Comunio webpage not available.' | ||
| sys.exit(1) | ||
| return | ||
| self.load_info() #Function to load the account information | ||
| def load_info(self): | ||
| ''' Get info from account logged ''' | ||
| ''' Get info from logged account ''' | ||
| headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain",'Referer': 'http://'+self.domain+'/login.phtml',"User-Agent": user_agent} | ||
@@ -57,9 +56,11 @@ req = self.session.get('http://'+self.domain+'/team_news.phtml',headers=headers).content | ||
| print estado.strip() | ||
| sys.exit(1) | ||
| return | ||
| [s.extract() for s in soup('strong')] | ||
| if (soup.find('div',{'id':'userid'}) != None): | ||
| self.id = soup.find('div',{'id':'userid'}).p.text.strip()[2:] | ||
| self.myid = soup.find('div',{'id':'userid'}).p.text.strip()[2:] | ||
| self.money = int(soup.find('div',{'id':'manager_money'}).p.text.strip().replace(".","")[:-2]) | ||
| self.teamvalue = int(soup.find('div',{'id':'teamvalue'}).p.text.strip().replace(".","")[:-2]) | ||
| self.community_id = soup.find('link')['href'][24:] | ||
| self.username = soup.find('div',{'id':'username'}).p.a.text | ||
@@ -76,3 +77,3 @@ def get_money(self): | ||
| '''Get my id''' | ||
| return self.id | ||
| return self.myid | ||
@@ -82,2 +83,6 @@ def get_title(self): | ||
| return self.title | ||
| def get_username(self): | ||
| '''Name of the user''' | ||
| return self.username | ||
@@ -175,2 +180,3 @@ def get_news(self): | ||
| '''Get id using name football player''' | ||
| number = 0 | ||
| name=name.title().replace(" ", "+") | ||
@@ -237,3 +243,3 @@ headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain",'Referer': 'http://'+self.domain+'/team_news.phtml',"User-Agent": user_agent} | ||
| def players_onsale(self, only_computer=False): | ||
| def players_onsale(self, community_id, only_computer=False): | ||
| ''' | ||
@@ -243,57 +249,26 @@ Returns the football players currently on sale | ||
| ''' | ||
| reintentos=0 | ||
| headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain",'Referer': 'http://'+self.domain+'/team_news.phtml',"User-Agent": user_agent} | ||
| req = self.session.get('http://'+self.domain+'/teamInfo.phtml?tid=' + community_id, headers=headers).content | ||
| soup = BeautifulSoup(req) | ||
| current_year = dt.today().year | ||
| current_month = dt.today().month | ||
| display = Display(visible=0, size=(800, 600)) | ||
| display.start() | ||
| xpaths = { 'usernameTxtBox': ".//*[@id='login-ubox']/input", | ||
| 'passwordTxtBox': ".//*[@id='login-pwbox']/input", | ||
| 'loginButton' : ".//*[@id='login-box-wrapper']/a", | ||
| 'exchange_table': ".//*[@id='searchTextResults']" | ||
| } | ||
| browser = webdriver.Firefox() | ||
| browser.get("http://www.comunio.es/login.phtml") | ||
| browser.find_element_by_xpath(xpaths['usernameTxtBox']).clear() | ||
| browser.find_element_by_xpath(xpaths['usernameTxtBox']).send_keys(self.username) | ||
| browser.find_element_by_xpath(xpaths['passwordTxtBox']).clear() | ||
| browser.find_element_by_xpath(xpaths['passwordTxtBox']).send_keys(self.password) | ||
| browser.find_element_by_xpath(xpaths['loginButton']).click() | ||
| time.sleep(3) | ||
| # Esperaremos en el while hasta que termine de cargar el JS de la página | ||
| browser.get('http://www.comunio.es/exchangemarket.phtml') | ||
| time.sleep(3) | ||
| while True and reintentos < 20: | ||
| req = browser.page_source | ||
| soup = BeautifulSoup(req) | ||
| on_sale = [] | ||
| year_flag = 0 | ||
| try: | ||
| for i in soup.find('table',{'class','tablecontent03'}).find_all('tr')[2:]: | ||
| name = i.find_all('td')[0].text.strip() | ||
| team = i.find('span')['title'] | ||
| min_price = i.find_all('td')[2].text.replace(",","").strip() | ||
| market_price = i.find_all('td')[3].text.replace(",","").strip() | ||
| points = i.find_all('td')[4].text.strip().strip() | ||
| # Controlamos el cambio de año, ya que comunio no lo dá | ||
| if current_month <= 7 and int(i.find_all('td')[5].text[3:5]) > 7: | ||
| year_flag = 1 | ||
| date = str(current_year-year_flag)+i.find_all('td')[5].text[3:5]+i.find_all('td')[5].text[:2] | ||
| owner = i.find_all('td')[6].text.strip() | ||
| position = i.find_all('td')[7].text.strip() | ||
| # Comprobamos si solamente queremos los de la computadora o no | ||
| if (only_computer and owner == 'Computer') or not only_computer: | ||
| on_sale.append([name, team, min_price, market_price, points, date, owner, position]) | ||
| # Llegaremos al break cuando se haya cargado el JS y cargado la lista | ||
| if on_sale != []: | ||
| break | ||
| except Exception as e: | ||
| reintentos+=1 | ||
| print 'Error looking for players on sale "players_onsale": ', e | ||
| print 'Trying again (%s).' % reintentos | ||
| if reintentos == 10: | ||
| browser.get('http://www.comunio.es/exchangemarket.phtml') | ||
| time.sleep(3) | ||
| browser.quit() | ||
| display.stop() | ||
| on_sale = [] | ||
| year_flag = 0 | ||
| for i in soup.find_all('table',{'class','tablecontent03'})[2].find_all('tr')[1:]: | ||
| name = i.find_all('td')[0].text.strip() | ||
| team = i.find('img')['alt'] | ||
| min_price = i.find_all('td')[2].text.replace(".","").strip() | ||
| market_price = i.find_all('td')[3].text.replace(".","").strip() | ||
| points = i.find_all('td')[4].text.strip().strip() | ||
| # Controlamos el cambio de año, ya que comunio no lo dá | ||
| if current_month <= 7 and int(i.find_all('td')[5].text[3:5]) > 7: | ||
| year_flag = 1 | ||
| date = str(current_year-year_flag)+i.find_all('td')[5].text[3:5]+i.find_all('td')[5].text[:2] | ||
| owner = i.find_all('td')[6].text.strip() | ||
| position = i.find_all('td')[7].text.strip() | ||
| # Comprobamos si solamente queremos los de la computadora o no | ||
| if (only_computer and owner == 'Computer') or not only_computer: | ||
| on_sale.append([name, team, min_price, market_price, points, date, owner, position]) | ||
| return on_sale | ||
@@ -300,0 +275,0 @@ |
@@ -20,7 +20,7 @@ #!/usr/bin/env python | ||
| time.sleep(1) | ||
| myid=test.get_myid() | ||
| print "ID: %s" % (myid) | ||
| print "Money: %s" % test.get_money() | ||
| print "TeamValue: %s" % test.get_team_value() | ||
| print "Title: %s" % test.get_title() | ||
| print "ID: %s" % test.id | ||
| print "Money: %s" % test.money | ||
| print "TeamValue: %s" % test.teamvalue | ||
| print "Title: %s" % test.title | ||
| print "Community ID: %s" % test.community_id | ||
@@ -38,3 +38,3 @@ #=============================================================================== | ||
| # print '\n[*] Info user:' | ||
| # for i in test.info_user(myid): | ||
| # for i in test.info_user(test.id): | ||
| # print i | ||
@@ -47,3 +47,3 @@ #=============================================================================== | ||
| # print '\n[*] Lineup user:' | ||
| # for i in test.lineup_user(myid): | ||
| # for i in test.lineup_user(test.id): | ||
| # print i | ||
@@ -56,3 +56,3 @@ #=============================================================================== | ||
| # print '[*] Info community:\n' | ||
| # for i in test.info_community('communityID'): | ||
| # for i in test.info_community('test.community_id'): | ||
| # print i | ||
@@ -104,3 +104,3 @@ #=============================================================================== | ||
| # print '\n[*] Players on sale:' | ||
| # for player in test.players_onsale(only_computer=True): | ||
| # for player in test.players_onsale(test.community_id, only_computer=False): | ||
| # print player | ||
@@ -107,0 +107,0 @@ #=============================================================================== |
+3
-154
| Metadata-Version: 1.1 | ||
| Name: ComunioPy | ||
| Version: 1.0.1 | ||
| Version: 1.2 | ||
| Summary: API for comunio | ||
@@ -9,156 +9,5 @@ Home-page: https://github.com/jotacor/ComunioPy | ||
| License: MIT | ||
| Download-URL: https://github.com/jotacor/ComunioPy/archive/v1.0.1.tar.gz | ||
| Description: ComunioPy | ||
| ========= | ||
| Comunio API Python | ||
| Introduction | ||
| ------------ | ||
| It is a simple API to get the information from your Comunio account and use it for your benefit. | ||
| In this API you can see the difference between a player (football) and a user (who plays Comunio). | ||
| Comunio is a web game where you are a manager of a team. | ||
| Forked from: | ||
| [comuniopy-v0.1](https://github.com/sinkmanu/comuniopy) | ||
| Installation | ||
| ----------- | ||
| ``` | ||
| python setup.py install | ||
| ``` | ||
| Usage | ||
| ----- | ||
| ### Config file for testing | ||
| You can use a config file with the user and login for testing. | ||
| ``` | ||
| [comunio] | ||
| user=USERNAME | ||
| passwd=PASSWORD | ||
| ``` | ||
| ### Login into your account and get the information | ||
| ``` | ||
| ComunioPy import Comunio | ||
| test = Comunio(USER,PASS,LEAGUE) | ||
| test.login() | ||
| uid = test.get_myid() | ||
| money = test.get_money() | ||
| teamvalue = test.team_value() | ||
| ``` | ||
| ### Get the latest news from your community | ||
| ``` | ||
| from ComunioPy import Comunio | ||
| test = Comunio(USER,PASS,LEAGUE) | ||
| test.login() | ||
| news = [] | ||
| news = test.get_news() | ||
| ``` | ||
| ### Functions and methods | ||
| #### login() | ||
| #### logout() | ||
| #### load_info() | ||
| ``` | ||
| This function is included in login() | ||
| ``` | ||
| #### get_money(): string | ||
| #### get_myid(): string | ||
| #### get_team_value():string | ||
| #### get_title():string | ||
| #### get_news():list | ||
| #### standings():list | ||
| ``` | ||
| Get the standings of the community and return a list with the elements: | ||
| position uid player points teamvalue | ||
| ``` | ||
| #### info_player(userid): list | ||
| ``` | ||
| Get the information of a user and return a list with: | ||
| name email community_name points name number_notices list_of_players | ||
| ``` | ||
| #### lineup_user(userid): list | ||
| ``` | ||
| Return a list with the name of players | ||
| ``` | ||
| #### info_comunity(teamid): list | ||
| ``` | ||
| position uid player points teamvalue | ||
| ``` | ||
| #### info_player(playerid): list | ||
| ``` | ||
| Return info about the football player. | ||
| [name,position,team,points,price] | ||
| ``` | ||
| #### info_player_id(name): string | ||
| ``` | ||
| Return ID of the football player name. | ||
| ``` | ||
| #### club(clubid): (string,list) | ||
| ``` | ||
| Get info about a real team players using a ID | ||
| teamname,[player list] | ||
| ``` | ||
| #### team_id(team): string | ||
| Returns the ID of a team to use with test.club(cid) | ||
| ``` | ||
| cid = test.team_id('Valencia') | ||
| players = [] | ||
| club,players = test.club(cid) | ||
| ``` | ||
| #### user_id(user):string | ||
| Get the ID of a real user. | ||
| ``` | ||
| pid = test.user_id('username') | ||
| info = [] | ||
| info = test.user_info(pid) | ||
| ``` | ||
| #### players_onsale(only_computer=False): list(list) | ||
| Returns the football players currently on sale. | ||
| Yout could retrieve only computer players on sale. | ||
| ``` | ||
| [[name, team, min_price, market_price, points, date, owner, position]] | ||
| ``` | ||
| #### bids_to_you(): list(list) | ||
| Get bids made to you. | ||
| ``` | ||
| [[player,owner,team,money,date,datechange,status],] | ||
| ``` | ||
| #### bids_from_you(): list(list) | ||
| Get your bids made for. | ||
| ``` | ||
| [[player,owner,team,money,date,datechange,status],] | ||
| ``` | ||
| Author | ||
| ------ | ||
| Javier Corbín (javi.corbin@gmail.com/[@korbin](https://twitter.com/korbin)/[Website](http://www.micolabs.com)) | ||
| Download-URL: https://github.com/jotacor/ComunioPy/archive/v1.2.tar.gz | ||
| Description: Scraping of the webpage Comunio | ||
| Keywords: comunio,API | ||
| Platform: UNKNOWN |
+13
-12
@@ -5,15 +5,16 @@ #!/usr/bin/env python | ||
| from distutils.core import setup | ||
| setup( | ||
| name = 'ComunioPy', | ||
| packages = ['ComunioPy'], | ||
| version = '1.0.1', | ||
| description = 'API for comunio', | ||
| license = 'MIT', | ||
| long_description = open('README.md', 'rt').read(), | ||
| author = 'Javier Corbín', | ||
| author_email = 'javi.corbin@gmail.com', | ||
| url = 'https://github.com/jotacor/ComunioPy', | ||
| download_url = 'https://github.com/jotacor/ComunioPy/archive/v1.0.1.tar.gz', | ||
| keywords = ['comunio', 'API'], | ||
| classifiers = [], | ||
| name = 'ComunioPy', | ||
| packages = ['ComunioPy'], | ||
| version = '1.2', | ||
| description = 'API for comunio', | ||
| license = 'MIT', | ||
| author = 'Javier Corbín', | ||
| author_email = 'javi.corbin@gmail.com', | ||
| url = 'https://github.com/jotacor/ComunioPy', | ||
| download_url = 'https://github.com/jotacor/ComunioPy/archive/v1.2.tar.gz', | ||
| keywords = ['comunio', 'API'], | ||
| classifiers = [], | ||
| long_description = 'Scraping of the webpage Comunio' | ||
| ) |
-151
| ComunioPy | ||
| ========= | ||
| Comunio API Python | ||
| Introduction | ||
| ------------ | ||
| It is a simple API to get the information from your Comunio account and use it for your benefit. | ||
| In this API you can see the difference between a player (football) and a user (who plays Comunio). | ||
| Comunio is a web game where you are a manager of a team. | ||
| Forked from: | ||
| [comuniopy-v0.1](https://github.com/sinkmanu/comuniopy) | ||
| Installation | ||
| ----------- | ||
| ``` | ||
| python setup.py install | ||
| ``` | ||
| Usage | ||
| ----- | ||
| ### Config file for testing | ||
| You can use a config file with the user and login for testing. | ||
| ``` | ||
| [comunio] | ||
| user=USERNAME | ||
| passwd=PASSWORD | ||
| ``` | ||
| ### Login into your account and get the information | ||
| ``` | ||
| ComunioPy import Comunio | ||
| test = Comunio(USER,PASS,LEAGUE) | ||
| test.login() | ||
| uid = test.get_myid() | ||
| money = test.get_money() | ||
| teamvalue = test.team_value() | ||
| ``` | ||
| ### Get the latest news from your community | ||
| ``` | ||
| from ComunioPy import Comunio | ||
| test = Comunio(USER,PASS,LEAGUE) | ||
| test.login() | ||
| news = [] | ||
| news = test.get_news() | ||
| ``` | ||
| ### Functions and methods | ||
| #### login() | ||
| #### logout() | ||
| #### load_info() | ||
| ``` | ||
| This function is included in login() | ||
| ``` | ||
| #### get_money(): string | ||
| #### get_myid(): string | ||
| #### get_team_value():string | ||
| #### get_title():string | ||
| #### get_news():list | ||
| #### standings():list | ||
| ``` | ||
| Get the standings of the community and return a list with the elements: | ||
| position uid player points teamvalue | ||
| ``` | ||
| #### info_player(userid): list | ||
| ``` | ||
| Get the information of a user and return a list with: | ||
| name email community_name points name number_notices list_of_players | ||
| ``` | ||
| #### lineup_user(userid): list | ||
| ``` | ||
| Return a list with the name of players | ||
| ``` | ||
| #### info_comunity(teamid): list | ||
| ``` | ||
| position uid player points teamvalue | ||
| ``` | ||
| #### info_player(playerid): list | ||
| ``` | ||
| Return info about the football player. | ||
| [name,position,team,points,price] | ||
| ``` | ||
| #### info_player_id(name): string | ||
| ``` | ||
| Return ID of the football player name. | ||
| ``` | ||
| #### club(clubid): (string,list) | ||
| ``` | ||
| Get info about a real team players using a ID | ||
| teamname,[player list] | ||
| ``` | ||
| #### team_id(team): string | ||
| Returns the ID of a team to use with test.club(cid) | ||
| ``` | ||
| cid = test.team_id('Valencia') | ||
| players = [] | ||
| club,players = test.club(cid) | ||
| ``` | ||
| #### user_id(user):string | ||
| Get the ID of a real user. | ||
| ``` | ||
| pid = test.user_id('username') | ||
| info = [] | ||
| info = test.user_info(pid) | ||
| ``` | ||
| #### players_onsale(only_computer=False): list(list) | ||
| Returns the football players currently on sale. | ||
| Yout could retrieve only computer players on sale. | ||
| ``` | ||
| [[name, team, min_price, market_price, points, date, owner, position]] | ||
| ``` | ||
| #### bids_to_you(): list(list) | ||
| Get bids made to you. | ||
| ``` | ||
| [[player,owner,team,money,date,datechange,status],] | ||
| ``` | ||
| #### bids_from_you(): list(list) | ||
| Get your bids made for. | ||
| ``` | ||
| [[player,owner,team,money,date,datechange,status],] | ||
| ``` | ||
| Author | ||
| ------ | ||
| Javier Corbín (javi.corbin@gmail.com/[@korbin](https://twitter.com/korbin)/[Website](http://www.micolabs.com)) | ||
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
18453
-31.29%5
-16.67%362
-7.18%