def getValue(section, key, default=None):
    section = section.lower()
    key = key.lower()
    try:
        return loads(conf.get(section, key))
    except Exception:
        return default
Example #2
0
def getValue(section, key, default=None):
    section = section.lower()
    key = key.lower()
    try:
        return loads(conf.get(section, key))
    except Exception:
        return default
Example #3
0
    def get_scene(self):
        """
        get the content from the RabbitPre scene
        :return: dict
        """
        url_content = urllib2.urlopen(self.url).read()
        soup = BeautifulSoup(url_content.decode('utf-8'), 'html.parser')

        soup_target = soup.body.script.string
        scene_content_for_rson = '{' + soup_target.split('{', 1)[1].rsplit('}', 1)[0] + '}'
        scene_content_rsoned = rson.loads(scene_content_for_rson)
        scene_content_jsoned = json.dumps(scene_content_rsoned)
        scene_content_dict = json.loads(scene_content_jsoned)
        return scene_content_dict
Example #4
0
 def parse(self, response):
     if response.url == 'http://www.ebay.com/sch/Accessory-Bundles-/176971/i.html':
         for url in response.xpath('//h3[@class="lvtitle"]//a/@href').extract():
             yield scrapy.Request(url)
     else:
         for script in response.xpath('//script/text()').extract():
             script = re.sub(r'\s+', ' ', script)
             match = re.match(r'^.+"imgArr" : (.+\]), "islarge".+$', script)
             item = EbayImagesItem()
             images = []
             if match:
                 for img in rson.loads(match.group(1)):
                     images.append(img['maxImageUrl'])
             item['image_urls'] = images
             yield item
    def test_output_sequential_journals(self):
        ldgr = Ledger(
            Column("Canadian cash", Cy.CAD, Role.asset, "{}"),
            Column("US cash", Cy.USD, Role.asset, "{}"),
            Column("Capital", Cy.CAD, Role.capital, "{}"),
            Column("Expense", Cy.CAD, Role.expense, "{}"),
            ref=Cy.CAD)
        cols = ldgr.columns

        for amount, col in zip(
            (Dl(200), Dl(0), Dl(200), Dl(0)), ldgr.columns.values()
        ):
            ldgr.commit(amount, col)

        out = io.StringIO()
        print(metadata(ldgr), file=out)
        print(journal(
            ldgr,
            ts=datetime.date(2013, 1, 1), note="Opening balance"),
            file=out)

        exchange = Exchange({(Cy.USD, Cy.CAD): Dl("1.2")})
        for args in ldgr.adjustments(exchange):
            ldgr.commit(*args)

        print(journal(
            ldgr,
            ts=datetime.date(2013, 1, 2), note="1 USD -> 1.20 CAD"),
            file=out)

        ldgr.commit(-20, cols["Canadian cash"])
        ldgr.commit(20, cols["Expense"])

        print(journal(
            ldgr,
            ts=datetime.date(2013, 1, 3), note="Buy food"),
            file=out)

        objs = rson.loads(out.getvalue())
        self.assertEqual(8, len(objs))
        self.assertEqual([180., 0., 200., 20., 0., 0.], objs[-1])
    def test_output_metadata(self):
        ldgr = Ledger(
            Column("Canadian cash", Cy.CAD, Role.asset, "{}"),
            Column("US cash", Cy.USD, Role.asset, "{}"),
            Column("Capital", Cy.CAD, Role.capital, "{}"),
            Column("Expense", Cy.CAD, Role.expense, "{}"),
            ref=Cy.CAD)

        m = metadata(ldgr)
        out = rson.loads(m)
        self.assertEqual(2, len(out))
        self.assertIn("header", out[0])
        self.assertEqual(
            tallywallet.common.__version__,
            str(out[0]["header"]["version"])
        )

        self.assertIn("ledger", out[1])
        # Two columns are added by ledger for USD and CAD trading
        self.assertEqual(6, len(out[1]["ledger"]["columns"]))
        self.assertEqual("CAD", out[1]["ledger"]["ref"])
    def test_output_journal(self):
        ldgr = Ledger(
            Column("Canadian cash", Cy.CAD, Role.asset, "{}"),
            Column("US cash", Cy.USD, Role.asset, "{}"),
            Column("Capital", Cy.CAD, Role.capital, "{}"),
            Column("Expense", Cy.CAD, Role.expense, "{}"),
            ref=Cy.CAD)

        for amount, col in zip(
            (Dl(200), Dl(0), Dl(200), Dl(0)), ldgr.columns.values()
        ):
            (_, _, _, _, st) = ldgr.commit(amount, col)

        self.assertIs(Status.ok, st)
        t = journal(
            ldgr,
            ts=datetime.date(2013, 1, 1), note="Opening balance")
        out = rson.loads(t)
        self.assertEqual(2, len(out))
        self.assertEqual(
            {"ts": "2013-01-01", "note": "Opening balance"},
            out[0])
        self.assertEqual(6, len(out[1]))
        self.assertEqual(400, sum(out[1]))
Example #8
0
def parse_json(s):
    # s contains urls as "http://..." + "/album/album"
    s = s.replace('" + "', '')
    return rson.loads(s)
Example #9
0
data = iter(open('manual.txt', 'rb').read().splitlines())

result = []
for line in data:
    result.append(line)
    while line.endswith('::') and '..' not in line:
        result[-1] = line.replace(' (break)', '')
        pagebreak = line != result[-1]
        indent = line[:len(line) - len(line.lstrip())] + ' '
        index = len(result)
        for line in data:
            if line.strip() and not line.startswith(indent):
                break
            result.append(line)
        code = '\n'.join(result[index:])
        code = loads(code)
        code = dumps(code, indent=2)
        code = '\n'.join(indent + '   ' + x for x in code.splitlines())
        if pagebreak:
            result.append('.. page::')
            result.append('')
        result.append(indent[:-1] + 'Results in the following equivalent JSON::')
        result.append('')
        result.append(code)
        result.append('')
        result.append(line)

result.append('')
result = '\n'.join(result)

f = open('manual2.txt', 'wb')
Example #10
0
    args = channel.receive()

    session = Registry().connect(sqlite3, args["db"]).session
    initialise(session)

    org = session.query(Organisation).filter(
        Organisation.name == args["organisation"]).first()
    if org is None:
        channel.send("No org named {}".format(args["organisation"]))
        channel.send(None)
    else:
        channel.send(("organisation", org.uuid, org.name))

        with open(args["path"], 'r') as input_:
            objs = rson.loads(input_.read())
            for obj in objs:
                try:
                    session.add(
                        CatalogueItem(
                            name=obj["name"].strip(),
                            description=obj["description"].strip(),
                            note=obj["note"].strip(),
                            logo="headless",
                            organisation=org,
                            natrouted=obj["natrouted"],
                            uuid=obj["uuid"],
                        ))
                    session.commit()
                    channel.send((obj["uuid"], obj["name"].strip()))
                except Exception as e:
Example #11
0
#!/usr/bin/env python

import sys
import time
import os

sys.path.insert(0, '..')
sys.path.insert(0, 'simplejson')

from rson import loads
#from simplejson import loads
#from json import loads

strings = [open(os.path.join('styles', x), 'rb').read() for x in os.listdir('styles') if x.endswith('json')]

endtime = time.time() + 10.0

i = 0
while time.time() < endtime:
    z = [loads(x) for x in strings]
    i += 1

print i