コード例 #1
0
ファイル: mypickle.py プロジェクト: grap3fruit/trelby
    def fromStr(self, vals, val, prefix):
        v = val.split(",")
        if len(v) != 3:
            return copy.deepcopy(self.defVal)

        r = util.str2int(v[0], 0, 0, 255)
        g = util.str2int(v[1], 0, 0, 255)
        b = util.str2int(v[2], 0, 0, 255)

        return util.MyColor(r, g, b)
コード例 #2
0
ファイル: mypickle.py プロジェクト: HuBandiT/trelby
    def fromStr(self, vals, val, prefix):
        v = val.split(",")
        if len(v) != 3:
            return copy.deepcopy(self.defVal)

        r = util.str2int(v[0], 0, 0, 255)
        g = util.str2int(v[1], 0, 0, 255)
        b = util.str2int(v[2], 0, 0, 255)

        return util.MyColor(r, g, b)
コード例 #3
0
ファイル: headers.py プロジェクト: 4thguy/trelby
    def load(self, s):
        a = util.fromUTF8(s).split(",", 4)

        if len(a) != 5:
            return

        self.line = util.str2int(a[0], 1, 1, 5)
        self.xoff = util.str2int(a[1], 0, -100, 100)

        l, c, self.isBold, self.isItalic, self.isUnderlined = \
            util.flags2bools(a[2], "lcbiu")

        if l:
            self.align = util.ALIGN_LEFT
        elif c:
            self.align = util.ALIGN_CENTER
        else:
            self.align = util.ALIGN_RIGHT

        self.text = a[4]
コード例 #4
0
ファイル: headers.py プロジェクト: HuBandiT/trelby
    def load(self, s):
        a = s.split(",", 4)

        if len(a) != 5:
            return

        self.line = util.str2int(a[0], 1, 1, 5)
        self.xoff = util.str2int(a[1], 0, -100, 100)

        l, c, self.isBold, self.isItalic, self.isUnderlined = \
            util.flags2bools(a[2], "lcbiu")

        if l:
            self.align = util.ALIGN_LEFT
        elif c:
            self.align = util.ALIGN_CENTER
        else:
            self.align = util.ALIGN_RIGHT

        self.text = a[4]
コード例 #5
0
ファイル: mypickle.py プロジェクト: HuBandiT/trelby
    def fromStr(self, vals, val, prefix):
        # 1000 is totally arbitrary, increase if needed
        count = util.str2int(val, -1, -1, 1000)
        if count == -1:
            return copy.deepcopy(self.defVal)

        tmp = []
        for i in range(1, count + 1):
            name = prefix + "/%d" % i

            if vals.has_key(name):
                res = self.itemType.fromStr(vals, vals[name], name)
                tmp.append(res)
                del vals[name]

        return tmp
コード例 #6
0
ファイル: mypickle.py プロジェクト: grap3fruit/trelby
    def fromStr(self, vals, val, prefix):
        # 1000 is totally arbitrary, increase if needed
        count = util.str2int(val, -1, -1, 1000)
        if count == -1:
            return copy.deepcopy(self.defVal)

        tmp = []
        for i in range(1, count + 1):
            name = prefix + "/%d" % i

            if vals.has_key(name):
                res = self.itemType.fromStr(vals, vals[name], name)
                tmp.append(res)
                del vals[name]

        return tmp
コード例 #7
0
ファイル: scrape_elections.py プロジェクト: hsoft/dgeq-rdf
def get_graph_from_soup(soup, dgeqid):
    graph = Graph()
    # extract election year
    header = soup('h2', id='e')[0].get_text()
    election_year = str2int(re.findall(r"\d{4}", header)[0])
    print(election_year)
    table = soup('table', class_='tableau')[0]
    rows = table('tr')
    current_division = None
    general_election_id = ns_election[dgeqid]
    graph.add((general_election_id, RDF.type, ns_type.ProvincialGeneralElection))
    graph.add((general_election_id, ns_property.year, Literal(election_year)))
    for row in rows:
        if not row.td: # header row, skip
            continue
        if 'circonscription-precedante' in row.td.attrs.get('class', ()): # division name row
            name = row.td.get_text().strip() 
            current_division = ns_division[str2id(name)]
            graph.add((current_division, RDF.type, ns_type.ProvincialDivision))
            graph.add((current_division, DC.description, Literal(name)))
            first = True
            election_id = BNode()
            graph.add((election_id, RDF.type, ns_type.ProvincialElection))
            graph.add((election_id, ns_property.generalElection, general_election_id))
            graph.add((election_id, ns_property.division, current_division))
        elif row.td.attrs.get('colspan') == '4': # summary row
            summary = row.td.get_text().strip()
            matches = re.findall(r"(?<=:)[\s\d]+", summary)
            graph.add((election_id, ns_property.validVoteCount, Literal(str2int(matches[0]))))
            graph.add((election_id, ns_property.invalidVoteCount, Literal(str2int(matches[1]))))
            graph.add((election_id, ns_property.totalVoteCount, Literal(str2int(matches[2]))))
            graph.add((election_id, ns_property.admissibleVoterCount, Literal(str2int(matches[3]))))
        else: # normal row
            cells = row.find_all('td')
            name = cells[0].get_text().strip()
            m = re.match(r"(.+?), (.+) \((.+)\)", name)
            lastname = m.group(1)
            firstname = m.group(2)
            party_id = str2party(m.group(3))
            candidate_id = ns_candidate[str2id(lastname + '_' + firstname)]
            votes = str2int(cells[1].get_text())
            graph.add((candidate_id, RDF.type, ns_type.ProvincialCandidate))
            save_person(graph, candidate_id, firstname, lastname)
            run_id = BNode()
            graph.add((run_id, RDF.type, ns_type.ProvincialCandidateRun))
            graph.add((run_id, ns_property.runningCandidate, candidate_id))
            graph.add((run_id, ns_property.election, election_id))
            graph.add((run_id, ns_property.runningFor, party_id))
            graph.add((run_id, ns_property.voteCount, Literal(votes)))
            if first:
                graph.add((run_id, ns_property.won, Literal(True)))
                first = False
    return graph
コード例 #8
0
ファイル: titles.py プロジェクト: 4thguy/trelby
    def load(self, s):
        a = util.fromUTF8(s).split(",", 6)

        if len(a) != 7:
            return

        self.x = util.str2float(a[0], 0.0)
        self.y = util.str2float(a[1], 0.0)
        self.size = util.str2int(a[2], 12, 4, 288)

        self.isCentered, self.isRightJustified, self.isBold, self.isItalic, \
            self.isUnderlined = util.flags2bools(a[3], "crbiu")

        tmp = { "Courier" : pml.COURIER,
                "Helvetica" : pml.HELVETICA,
                "Times" : pml.TIMES_ROMAN }

        self.font = tmp.get(a[4], pml.COURIER)
        self.items = util.unescapeStrings(a[6])
コード例 #9
0
    def load(self, s):
        a = util.fromUTF8(s).split(",", 6)

        if len(a) != 7:
            return

        self.x = util.str2float(a[0], 0.0)
        self.y = util.str2float(a[1], 0.0)
        self.size = util.str2int(a[2], 12, 4, 288)

        self.isCentered, self.isRightJustified, self.isBold, self.isItalic, \
            self.isUnderlined = util.flags2bools(a[3], "crbiu")

        tmp = {
            "Courier": pml.COURIER,
            "Helvetica": pml.HELVETICA,
            "Times": pml.TIMES_ROMAN
        }

        self.font = tmp.get(a[4], pml.COURIER)
        self.items = util.unescapeStrings(a[6])
コード例 #10
0
ファイル: mypickle.py プロジェクト: HuBandiT/trelby
 def fromStr(self, vals, val, prefix):
     return util.str2int(val, self.defVal, self.minVal, self.maxVal)
コード例 #11
0
ファイル: mypickle.py プロジェクト: grap3fruit/trelby
 def fromStr(self, vals, val, prefix):
     return util.str2int(val, self.defVal, self.minVal, self.maxVal)