from discord.ext import commands
import json

import aiofiles
from lxml import etree

class Wolfram:
    chars = {0xf74c: 'd',
             0xf74d: 'e',
             0xf74e: 'i',
             0xf74e: 'j',
             0xf7d9: ' = ',
             }
    def __init__(self, bot):
        self.bot = bot
        self.url = 'http://api.wolframalpha.com/v2/query'
        with open('config.json') as file:
            data = json.load(file)
        self.key = data['wolfram_key']

    @commands.command(aliases=['wolf', 'w'])
    async def wolfram(self, ctx, *, inp):
        async with ctx.typing():
            result = await self.search(inp)
        await ctx.send(result)

    async def search(self, inp):
        params = {'input': inp, 'appid': self.key, 'format': 'plaintext'}
        async with self.bot.session.get(self.url, params=params) as resp:
            text = await resp.text() 
        async with aiofiles.open('request.txt', 'w', encoding='utf8') as file:
            await file.write(text)
            root = etree.fromstring(text.encode(), etree.XMLParser())
            try:
                result = root.xpath("//pod[@title!='Input interpretation']/subpod/plaintext/text()")[0]
            except IndexError:
                result = 'No results found.'
        return result.translate(self.chars)

def setup(bot):
    bot.add_cog(Wolfram(bot))

@@ -116,16 +116,17 @@
 xf74c: '
+ 
 d',%0A    
@@ -1085,16 +1085,211 @@
    try:%0A
+                interpretation = root.xpath(%22//pod%5B@title='Input interpretation'%5D/subpod/plaintext/text()%22)%5B0%5D%0A            except IndexError:%0A                interpretation = ''%0A            try:%0A
         
@@ -1376,32 +1376,32 @@
 ext/text()%22)%5B0%5D%0A
-
             exce
@@ -1474,23 +1474,53 @@
   return
+ ('%5Cn'.join((interpretation,
  result
+))
 .transla

Input interpratation