Exemplo n.º 1
0
    def test_xml_fromstring(self):
        'xml_fromstring=False does not convert types'
        x2j_convert = self.check_data(xmljson.GData(xml_fromstring=True))
        x2j_strings = self.check_data(xmljson.GData(xml_fromstring=str))
        x2j_convert('{"x": {"$t": 1}}', '<x>1</x>')
        x2j_strings('{"x": {"$t": "1"}}', '<x>1</x>')
        x2j_convert('{"x": {"$t": true}}', '<x>true</x>')
        x2j_strings('{"x": {"$t": "true"}}', '<x>true</x>')

        j2x_convert = self.check_etree(xmljson.GData(xml_tostring=True))
        j2x_strings = self.check_etree(xmljson.GData(xml_tostring=str))
        j2x_convert({"x": {"$t": True}}, '<x>true</x>')
        j2x_strings({"x": {"$t": True}}, '<x>True</x>')
        j2x_convert({"x": {"$t": False}}, '<x>false</x>')
        j2x_strings({"x": {"$t": False}}, '<x>False</x>')
Exemplo n.º 2
0
    def test_cli(self):
        dialects = [
            xmljson.Abdera(),
            xmljson.BadgerFish(),
            xmljson.Cobra(),
            xmljson.GData(),
            xmljson.Parker(),
            xmljson.Yahoo()
        ]

        for dialect in dialects:
            for path in [
                    'abdera-1.xml', 'abdera-2.xml', 'abdera-3.xml',
                    'abdera-4.xml'
            ]:
                in_file = io.open(os.path.join(_folder, path),
                                  encoding='utf-8')
                out_file = openwrite(self.tmp)
                main(in_file, out_file, dialect)
                in_file = io.open(os.path.join(_folder, path),
                                  encoding='utf-8')
                out_file = io.open(self.tmp, encoding='utf-8')
                with closing(in_file), closing(out_file):
                    self.assertEqual(json.load(out_file),
                                     dialect.data(parse(in_file).getroot()))
Exemplo n.º 3
0
import asyncio
from xml.etree.ElementTree import fromstring

import xmljson
from async_timeout import timeout
from bs4 import BeautifulSoup

XML_PARSER = xmljson.GData(dict_type=dict)
DEMOTIVATOR_URL = "https://despair.com/collections/posters"
TRIVIA_CATEGORIES_URL = "https://opentdb.com/api_category.php"
FORECAST_XML = [
    "IDN11060.xml",  # NSW/ACT
    "IDD10207.xml",  # NT
    "IDQ11295.xml",  # QLD
    "IDS10044.xml",  # SA
    "IDT16710.xml",  # TAS
    "IDV10753.xml",  # VIC
    "IDW14199.xml",  # WA
]
WEATHER_XML = [
    "IDN60920.xml",  # NSW/ACT
    "IDD60920.xml",  # NT
    "IDQ60920.xml",  # QLD
    "IDS60920.xml",  # SA
    "IDT60920.xml",  # TAS
    "IDV60920.xml",  # VIC
    "IDW60920.xml",  # WA
]


async def get_demotivators(session):