Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import gspread
- from oauth2client.service_account import ServiceAccountCredentials
- scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
- "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
- credbot = ServiceAccountCredentials.from_json_keyfile_name("credbot.json", scope)
- client = gspread.authorize(credbot)
- sheet = client.open("Definite Guild Daily XP").sheet1
- data = requests.get("https://api.hypixel.net/guild?key=lol&name=Definite").json()
- # @bot.command()
- # @commands.has_role("Guild Staff")
- # @commands.cooldown(1, 45, commands.BucketType.user)
- # async def markgxp(ctx):
- # await ctx.channel.purge(limit=1)
- # embed = discord.Embed(title="You Have Marked the Weekly GXP", color=0x77bb40)
- # embed.set_author(name="View the Weekly GXP Document", url="https://shorturl.at/fzJ08")
- # embed.set_footer(text="This command has a 45 second cooldown!")
- # await ctx.author.send(embed=embed)
- xpHist = []
- names = []
- for count in range(len(data['guild']['members'])): # For every guild member:
- res = requests.get("https://playerdb.co/api/player/minecraft/" + data['guild']['members'][count]['uuid']) # Response from server
- if res.status_code != 200: # If it wasn't a success, continue the loop and print a message
- ctx.author.send("Error 1: Invaild name from player database API!")
- continue
- name = res.json()['data']['player']['username'] # We know it was successful if we got to this point, so it's safe to try and get data from our response
- names.append(name)
- # Members' GXP
- xp = data['guild']['members'][count]['expHistory']
- xp = sum(xp.values())
- xpHist.append(xp)
- # Weekly Total
- wTotal = sum(xpHist)
- print(xpHist)
- ## Google Sheets
- # Sorting and printing names list
- # Nesting values into lists in the list
- def splitNames(names):
- return [[i] for i in names]
- def splitXP(xpHist):
- return [[i] for i in xpHist]
- for i in range(3):
- names.insert(0, None)
- xpHist.insert(0, None)
- # Pushes updates from the lists to the google sheet #
- sheet.update('B:B', splitNames(names))
- sheet.update('C:C', splitXP(xpHist))
- lastRow = sheet.row_count
- lastRow = lastRow
- if sheet.append_row(['Total', wTotal]):
- sheet.delete_rows(lastRow)
- else:
- print("Could not delete outdated 'Total' row!"
Add Comment
Please, Sign In to add comment