Skip to content

Instantly share code, notes, and snippets.

@3mrdev
Created September 21, 2022 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3mrdev/beec3c18eb2a74a4587fef2a76e6ff25 to your computer and use it in GitHub Desktop.
Save 3mrdev/beec3c18eb2a74a4587fef2a76e6ff25 to your computer and use it in GitHub Desktop.
Get Top Users By Country Odoo (work in progress)
# Import required modules
from lxml import html
import requests
import json
class Utils():
cookies = {'session_id': ''}
def getUsers(self):
users = []
for i in range(1,2):
# Request the page
page = requests.get('https://www.odoo.com/profile/users/page/'+str(i))
# Parsing the page
# (We need to use page.content rather than
# page.text because html.fromstring implicitly
# expects bytes as input.)
tree = html.fromstring(page.content)
# Get element using XPath
rows = tree.xpath("//tr[contains(concat(' ', normalize-space(@class), ' '), ' o_wprofile_pointer ')]")
# names = rows[0].xpath("//td[3]/span[1]")
for k in range(0,len(rows)):
uid = rows[k].get("onclick").split("'")[1].split("/")[3]
print(uid)
users.append(utill.getUserRank(uid))
return json.dumps(users)
def getUserRank(self,uid):
user = {}
# Request the page
page = requests.get('https://www.odoo.com/profile/user/'+uid, cookies=self.cookies)
# Parsing the page
# (We need to use page.content rather than
# page.text because html.fromstring implicitly
# expects bytes as input.)
tree = html.fromstring(page.content)
# Get element using XPath
city = tree.xpath("//div[contains(concat(' ', normalize-space(@class), ' '), ' o_wprofile_header ')]/div[2]/div/div[2]/div[2]/div[1]/span[1]")
country = tree.xpath("//div[contains(concat(' ', normalize-space(@class), ' '), ' o_wprofile_header ')]/div[2]/div/div[2]/div[2]/div[1]/span[2]/span[1]")
name = tree.xpath("//h1[contains(concat(' ', normalize-space(@class), ' '), ' o_card_people_name ')]/span[1]")
score = tree.xpath("//div[contains(concat(' ', normalize-space(@class), ' '), ' o_wprofile_progress_circle ')]/div/small/span[1]")
upvotes = tree.xpath("//tr[contains(concat(' ', normalize-space(@id), ' '), ' profile_abstract_info_company ')]/td[1]/span/span[1]")
downvotes = tree.xpath("//tr[contains(concat(' ', normalize-space(@id), ' '), ' profile_abstract_info_company ')]/td[1]/span/span[2]")
user["name"] = name[0].text
user["city"] = city[0].text
if country:
user["country"] = country[0].text
user["score"] = (int(score[0].text.split(",")[0]) * 1000) + int(score[0].text.split(",")[1])
if upvotes:
user["upvotes"] = int(upvotes[0].text)
if downvotes:
user["downvotes"] = int(downvotes[0].text)
print(json.dumps(user))
return user
utill = Utils()
print(utill.getUsers())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment