예제 #1
0
    def _setRecord(self, record, row):
        for dstColumn, srcColumn in self.Columns.items():
            if srcColumn and row.find(srcColumn) is not None:
                rawData = row.find(srcColumn).text
                if rawData:
                    if srcColumn == 'Income':
                        value = QtCore.QDate.fromString(rawData, 'ddMMyyyy')
                    elif srcColumn == 'Year' and rawData == 'N/A':
                        value = None
                    elif srcColumn in ['Nominal', 'Diameter', 'Thickness',
                                       'ReversRotation', 'Weight']:
                        if rawData == '0':
                            value = None
                        else:
                            value = rawData
                    elif srcColumn == 'Duplicates':
                        if rawData == '0':
                            value = None
                        else:
                            value = int(rawData) + 1
                    elif srcColumn in ['Price', 'CatalogPrice']:
                        if rawData == '0':
                            value = None
                        else:
                            try:
                                value = stringToMoney(rawData)
                            except ValueError:
                                value = None
                    else:
                        value = rawData

                    record.setValue(dstColumn, value)

            if dstColumn == 'status':
                value = 'owned'
                # Process Status fields that contain translated text
                element = row.find('ItemStatus').find('Status')
                if element.text in ['Private', 'Частный', 'Прыватны']:
                    value = 'demo'
                elif element.text in ['Lost', 'Утерян', 'Згублен']:
                    value = 'wish'
                elif element.text in ['Sold', 'Продан', 'Прададзен']:
                    value = 'sold'

                record.setValue(dstColumn, value)

        imgFields = ['obverseimg', 'reverseimg', 'photo1',
                     'photo2', 'photo3', 'photo4']
        imageNo = 0
        imageElements = row.find('Images')
        if imageElements is not None:
            for element in imageElements.iter('Data'):
                if element.text:
                    value = base64.b64decode(bytes(element.text, 'latin-1'))
                    image = QtGui.QImage()
                    image.loadFromData(value)
                    record.setValue(imgFields[imageNo], image)
                    imageNo = imageNo + 1

        record.setValue('title', self.__generateTitle(record))
    def _parsePage(self):
        items = []
        hostname = 'http://' + urllib.parse.urlparse(self.url).hostname
        table = self.html.cssselect('table tr')[4].cssselect('table td')[1].cssselect('table')[0]

        for tr in table.cssselect('tr'):
            tds = tr.cssselect('td')
            if len(tds) >= 9:
                lotnum = str(tds[0].text_content()).strip()
                url = hostname + tds[1].cssselect('a')[0].attrib['href']
                denomination = str(tds[2].text_content()).strip()
                year = str(tds[3].text_content())
                mintmark = str(tds[4].text_content())
                material = str(tds[5].text_content())
                grade = _stringToGrade(tds[6].text_content())
                buyer = str(tds[7].text_content())
                bids = int(tds[8].text_content())
                price = stringToMoney(tds[9].text_content())
                totalPayPrice = self.totalPayPrice(price)
                totalSalePrice = self.totalSalePrice(price)
                items.append({
                        'lotnum': lotnum, 'site': 'Аукцион',
                        'url': url, 'denomination': denomination, 'year': year,
                        'mintmark': mintmark, 'material': material,
                        'grade': grade, 'buyer': buyer, 'bids': bids,
                        'price': price, 'totalPayPrice': totalPayPrice,
                        'totalSalePrice': totalSalePrice})

        return items
    def _parsePage(self):
        items = []
        hostname = 'http://' + urllib.parse.urlparse(self.url).hostname

        item = self.html.cssselect('td#center')[0]
        item = item.cssselect('table table')[2]
        item = item.cssselect('td.smallText')
        if len(item) < 2:
            return []
        item = item[1]
        content = item.cssselect('strong')[0].text_content()
        if content.find("Аукцион №") >= 0:
            site = 'Аукцион'
        else:
            site = 'Очный'

        auctionnum = content[content.find("№") + 1:]

        table = self.html.cssselect('table.productListing')[0]
        for tr in table.cssselect('tr.productListing-data'):
            tds = tr.cssselect('td')
            if len(tds) >= 9:
                lotnum = str(tds[0].text_content()).strip()
                url = hostname + tds[1].cssselect('a')[0].attrib['href']
                denomination = str(tds[1].text_content()).strip()
                year = str(tds[2].text_content())
                mintmark = str(tds[3].text_content())
                material = str(tds[4].text_content())
                grade = _stringToGrade(tds[5].text_content())
                bids = int(tds[6].text_content())
                buyer = str(tds[7].text_content())
                price = stringToMoney(tds[8].text_content())
                totalPayPrice = self.totalPayPrice(price)
                totalSalePrice = self.totalSalePrice(price)
                items.append({
                        'lotnum': lotnum, 'site': site, 'auctionnum': auctionnum,
                        'url': url, 'denomination': denomination, 'year': year,
                        'mintmark': mintmark, 'material': material,
                        'grade': grade, 'buyer': buyer, 'bids': bids,
                        'price': price, 'totalPayPrice': totalPayPrice,
                        'totalSalePrice': totalSalePrice})

        return items
예제 #4
0
    def save(self):
        # Clear unused fields
        status = self.items['status'].widget().data()
        if status in ('demo', 'wish'):
            for key in ('paydate', 'payprice', 'totalpayprice', 'saller',
                        'payplace', 'payinfo'):
                self.items[key].clear()
        if status in ('demo', 'wish', 'owned', 'sale', 'ordered', 'missing', 'bidding'):
            for key in ('saledate', 'saleprice', 'totalsaleprice', 'buyer',
                        'saleplace', 'saleinfo'):
                self.items[key].clear()

        settings = Settings()

        if settings['check_coin_title']:
            if not self.usedFields:
                if not self.items['title'].value():
                    result = QMessageBox.warning(
                        self, self.tr("Save"),
                        self.tr("Coin title not set. Save without title?"),
                        QMessageBox.Save | QMessageBox.No, QMessageBox.No)
                    if result != QMessageBox.Save:
                        return

        # Checking that TotalPrice not less than Price
        payprice_str = self.items['payprice'].value()
        totalpayprice_str = self.items['totalpayprice'].value()
        if totalpayprice_str:
            totalpayprice = stringToMoney(totalpayprice_str)
            if totalpayprice < 0:
                result = QMessageBox.warning(self, self.tr("Save"),
                                self.tr("Total paid price is negative. Save?"),
                                QMessageBox.Save | QMessageBox.No,
                                QMessageBox.No)
                if result != QMessageBox.Save:
                    return
        if payprice_str and totalpayprice_str:
            payprice = stringToMoney(payprice_str)
            if totalpayprice < payprice:
                result = QMessageBox.warning(self, self.tr("Save"),
                            self.tr("Pay price is great than total "
                                    "paid price. Save?"),
                            QMessageBox.Save | QMessageBox.No,
                            QMessageBox.No)
                if result != QMessageBox.Save:
                    return
        saleprice_str = self.items['saleprice'].value()
        totalsaleprice_str = self.items['totalsaleprice'].value()
        if totalsaleprice_str:
            totalsaleprice = stringToMoney(totalsaleprice_str)
            if totalsaleprice < 0:
                result = QMessageBox.warning(self, self.tr("Save"),
                                self.tr("Total bailed price is negative. Save?"),
                                QMessageBox.Save | QMessageBox.No,
                                QMessageBox.No)
                if result != QMessageBox.Save:
                    return
        if saleprice_str and totalsaleprice_str:
            saleprice = stringToMoney(saleprice_str)
            if saleprice < totalsaleprice:
                result = QMessageBox.warning(self, self.tr("Save"),
                            self.tr("Sale price is less than total "
                                    "bailed price. Save?"),
                            QMessageBox.Save | QMessageBox.No,
                            QMessageBox.No)
                if result != QMessageBox.Save:
                    return

        for item in self.items.values():
            value = item.value()
            if isinstance(value, str):
                value = value.strip()
            self.record.setValue(item.field(), value)

        for image_field in ImageFields:
            item = self.items[image_field]
            value = item.widget().title
            if isinstance(value, str):
                value = value.strip()
            self.record.setValue(image_field + '_title', value)

        if settings['check_coin_duplicate']:
            if not self.usedFields:
                if self.model.isExist(self.record):
                    result = QMessageBox.warning(
                        self, self.tr("Save"),
                        self.tr("Similar coin already exists. Save?"),
                        QMessageBox.Save | QMessageBox.No, QMessageBox.No)
                    if result != QMessageBox.Save:
                        return

        self.accept()
예제 #5
0
def textToFloat(text):
    if text:
        return stringToMoney(text)
    else:
        return 0
    def save(self):
        # Clear unused fields
        status = self.items['status'].widget().data()
        if status in ('demo', 'wish'):
            for key in ('paydate', 'payprice', 'totalpayprice', 'saller',
                        'payplace', 'payinfo'):
                self.items[key].clear()
        if status in ('demo', 'wish', 'owned', 'sale', 'ordered', 'missing', 'bidding'):
            for key in ('saledate', 'saleprice', 'totalsaleprice', 'buyer',
                        'saleplace', 'saleinfo'):
                self.items[key].clear()

        settings = Settings()

        if settings['check_coin_title']:
            if not self.usedFields:
                if not self.items['title'].value():
                    result = QMessageBox.warning(
                        self, self.tr("Save"),
                        self.tr("Coin title not set. Save without title?"),
                        QMessageBox.Save | QMessageBox.No, QMessageBox.No)
                    if result != QMessageBox.Save:
                        return

        # Checking that TotalPrice not less than Price
        payprice_str = self.items['payprice'].value()
        totalpayprice_str = self.items['totalpayprice'].value()
        if totalpayprice_str:
            totalpayprice = stringToMoney(totalpayprice_str)
            if totalpayprice < 0:
                result = QMessageBox.warning(self, self.tr("Save"),
                                self.tr("Total paid price is negative. Save?"),
                                QMessageBox.Save | QMessageBox.No,
                                QMessageBox.No)
                if result != QMessageBox.Save:
                    return
        if payprice_str and totalpayprice_str:
            payprice = stringToMoney(payprice_str)
            if totalpayprice < payprice:
                result = QMessageBox.warning(self, self.tr("Save"),
                            self.tr("Pay price is great than total "
                                    "paid price. Save?"),
                            QMessageBox.Save | QMessageBox.No,
                            QMessageBox.No)
                if result != QMessageBox.Save:
                    return
        saleprice_str = self.items['saleprice'].value()
        totalsaleprice_str = self.items['totalsaleprice'].value()
        if totalsaleprice_str:
            totalsaleprice = stringToMoney(totalsaleprice_str)
            if totalsaleprice < 0:
                result = QMessageBox.warning(self, self.tr("Save"),
                                self.tr("Total bailed price is negative. Save?"),
                                QMessageBox.Save | QMessageBox.No,
                                QMessageBox.No)
                if result != QMessageBox.Save:
                    return
        if saleprice_str and totalsaleprice_str:
            saleprice = stringToMoney(saleprice_str)
            if saleprice < totalsaleprice:
                result = QMessageBox.warning(self, self.tr("Save"),
                            self.tr("Sale price is less than total "
                                    "bailed price. Save?"),
                            QMessageBox.Save | QMessageBox.No,
                            QMessageBox.No)
                if result != QMessageBox.Save:
                    return

        for item in self.items.values():
            value = item.value()
            if isinstance(value, str):
                value = value.strip()
            self.record.setValue(item.field(), value)

        image_fields = ('obverseimg', 'reverseimg', 'edgeimg', 'varietyimg',
                        'photo1', 'photo2', 'photo3', 'photo4')
        for image_field in image_fields:
            item = self.items[image_field]
            value = item.widget().title
            if isinstance(value, str):
                value = value.strip()
            self.record.setValue(image_field + '_title', value)

        if settings['check_coin_duplicate']:
            if not self.usedFields:
                if self.model.isExist(self.record):
                    result = QMessageBox.warning(
                        self, self.tr("Save"),
                        self.tr("Similar coin already exists. Save?"),
                        QMessageBox.Save | QMessageBox.No, QMessageBox.No)
                    if result != QMessageBox.Save:
                        return

        self.accept()
def textToFloat(text):
    if text:
        return stringToMoney(text)
    else:
        return 0
    def _parse(self):
        for el in self.html.find_class('time_line2')[0].getchildren():
            self.html.find_class('time_line2')[0].remove(el)

        item = self.html.find_class('item')[0]
        if item.text_content().find("Лот закрыт") < 0:
            raise _NotDoneYetError()

        auctionItem = AuctionItem('Wolmar')

        values = item.find_class('values')

        content = values[1].text_content()
        bIndex = content.find("Лидер")
        bIndex = content[bIndex:].find(":") + bIndex
        eIndex = content[bIndex:].find("Количество ставок") + bIndex
        auctionItem.buyer = content[bIndex + 1:eIndex].strip()

        content = values[0].text_content()
        bIndex = content.find("Состояние")
        bIndex = content[bIndex:].find(":") + bIndex
        grade = content[bIndex + 1:].strip()
        auctionItem.grade = _stringToGrade(grade)

        auctionItem.info = self.url

        content = values[1].text_content()
        bIndex = content.find("Количество ставок")
        bIndex = content[bIndex:].find(":") + bIndex
        eIndex = content[bIndex:].find("Лот закрыт") + bIndex
        content = content[bIndex + 1:eIndex].strip()
        if int(content) < 2:
            QMessageBox.information(self.parent(),
                                self.tr("Parse auction lot"),
                                self.tr("Only 1 bid"),
                                QMessageBox.Ok)

        content = values[1].text_content()
        bIndex = content.find("Ставка")
        bIndex = content[bIndex:].find(":") + bIndex
        eIndex = content[bIndex:].find("Лидер") + bIndex
        content = content[bIndex + 1:eIndex].strip()
        auctionItem.price = stringToMoney(content)

        price = float(auctionItem.price)
        auctionItem.totalPayPrice = str(price + price * 10 / 100)

        price = float(auctionItem.price)
        auctionItem.totalSalePrice = str(price - price * 10 / 100)

        storedUrl = self.url

        auctionItem.images = []
        for tag in item.cssselect('a'):
            href = tag.attrib['href']
            url = urllib.parse.urljoin(storedUrl, href)
            self.readHtmlPage(url, 'windows-1251')
            content = self.html.cssselect('div')[0]
            for tag in content.cssselect('div'):
                tag.drop_tree()
            content = content.cssselect('img')[0]
            src = content.attrib['src']
            href = urllib.parse.urljoin(self.url, src)
            auctionItem.images.append(href)

        # Extract date from parent page
        url = urllib.parse.urljoin(storedUrl, '.')[:-1]
        self.readHtmlPage(url, 'windows-1251')
        content = self.html.find_class('content')[0].cssselect('h1 span')[0].text_content()
        date = content.split()[1]  # convert '(Закрыт 29.09.2011 12:30)' to '29.09.2011'
        auctionItem.date = QtCore.QDate.fromString(date, 'dd.MM.yyyy').toString(QtCore.Qt.ISODate)

        return auctionItem
    def _parse(self):
        try:
            self.html.get_element_by_id('siBidForm2')
            raise _NotDoneYetError()
        except KeyError:
            pass

        try:
            siWrapper = self.html.get_element_by_id('siWrapper')
        except KeyError:
            # Already moved to archive (after 2 months after done)
            raise _CanceledError()

        alleLink = siWrapper.find_class('alleLink')
        if alleLink:
            bidCount = int(alleLink[0].text_content().split()[0])
            if bidCount < 2:
                QMessageBox.information(self.parent(),
                                    self.tr("Parse auction lot"),
                                    self.tr("Only 1 bid"),
                                    QMessageBox.Ok)
        else:
            raise _CanceledError()

        auctionItem = AuctionItem('Молоток.Ру')

        content = siWrapper.find_class('timeInfo')[0].text_content()
        begin = content.find('(')
        end = content.find(',')
        date = content[begin + 1:end]  # convert 'завершен (19 Январь, 00:34:14)' to '19 января'
        day, month = date.split()
        month = month[0:3].lower()
        date = ' '.join((day, month))
        tmpDate = QtCore.QDate.fromString(date, 'dd MMM')
        currentDate = QtCore.QDate.currentDate()
        auctionItem.date = QtCore.QDate(currentDate.year(), tmpDate.month(),
                                    tmpDate.day()).toString(QtCore.Qt.ISODate)

        saller = siWrapper.find_class('sellerDetails')[0].cssselect('dl dt')[0].text_content()
        auctionItem.saller = saller.split()[0].strip()
        buyer = siWrapper.find_class('buyerInfo')[0].cssselect('strong')[1].text_content()
        auctionItem.buyer = buyer.strip()

        # Remove STYLE element
        for element in self.html.get_element_by_id('user_field').cssselect('style'):
            element.getparent().remove(element)
        info = self.html.get_element_by_id('user_field').text_content()
        auctionItem.info = info.strip() + '\n' + self.url

        index = self.doc.find("$('.galleryWrap').newGallery")
        bIndex = self.doc[index:].find("large:") + index
        bIndex = self.doc[bIndex:].find("[") + bIndex
        eIndex = self.doc[bIndex:].find("]") + bIndex
        images = self.doc[bIndex + 1:eIndex].strip()
        images = images.replace('"', '')
        auctionItem.images = images.split(',')

        content = siWrapper.get_element_by_id('itemFinishBox2').cssselect('strong')[0].text_content()
        auctionItem.price = stringToMoney(content)

        element = siWrapper.get_element_by_id('paymentShipment').cssselect('dd strong')
        if element:
            content = element[0].text_content()
            shipmentPrice = stringToMoney(content)
            auctionItem.totalPayPrice = str(auctionItem.price + shipmentPrice)
        else:
            auctionItem.totalPayPrice = auctionItem.price

        auctionItem.totalSalePrice = self.totalSalePrice(auctionItem)

        return auctionItem
예제 #10
0
    def save(self):
        # Clear unused fields
        if self.items['status'].widget().data() in ['demo', 'wish']:
            for key in [
                    'paydate', 'payprice', 'totalpayprice', 'saller',
                    'payplace', 'payinfo', 'saledate', 'saleprice',
                    'totalsaleprice', 'buyer', 'saleplace', 'saleinfo'
            ]:
                self.items[key].clear()
        elif self.items['status'].widget().data() in [
                'owned', 'sale', 'ordered'
        ]:
            for key in [
                    'saledate', 'saleprice', 'totalsaleprice', 'buyer',
                    'saleplace', 'saleinfo'
            ]:
                self.items[key].clear()

        if not self.usedFields:
            if not self.items['title'].value():
                result = QMessageBox.warning(
                    self, self.tr("Save"),
                    self.tr("Coin title not set. Save without title?"),
                    QMessageBox.Save | QMessageBox.No, QMessageBox.No)
                if result != QMessageBox.Save:
                    return

        # Checking that TotalPrice not less than Price
        payprice_str = self.items['payprice'].value()
        totalpayprice_str = self.items['totalpayprice'].value()
        if totalpayprice_str:
            totalpayprice = stringToMoney(totalpayprice_str)
            if totalpayprice < 0:
                result = QMessageBox.warning(
                    self, self.tr("Save"),
                    self.tr("Total paid price is negative. Save?"),
                    QMessageBox.Save | QMessageBox.No, QMessageBox.No)
                if result != QMessageBox.Save:
                    return
        if payprice_str and totalpayprice_str:
            payprice = stringToMoney(payprice_str)
            if totalpayprice < payprice:
                result = QMessageBox.warning(
                    self, self.tr("Save"),
                    self.tr("Pay price is great than total "
                            "paid price. Save?"),
                    QMessageBox.Save | QMessageBox.No, QMessageBox.No)
                if result != QMessageBox.Save:
                    return
        saleprice_str = self.items['saleprice'].value()
        totalsaleprice_str = self.items['totalsaleprice'].value()
        if totalsaleprice_str:
            totalsaleprice = stringToMoney(totalsaleprice_str)
            if totalsaleprice < 0:
                result = QMessageBox.warning(
                    self, self.tr("Save"),
                    self.tr("Total bailed price is negative. Save?"),
                    QMessageBox.Save | QMessageBox.No, QMessageBox.No)
                if result != QMessageBox.Save:
                    return
        if saleprice_str and totalsaleprice_str:
            saleprice = stringToMoney(saleprice_str)
            if saleprice < totalsaleprice:
                result = QMessageBox.warning(
                    self, self.tr("Save"),
                    self.tr("Sale price is less than total "
                            "bailed price. Save?"),
                    QMessageBox.Save | QMessageBox.No, QMessageBox.No)
                if result != QMessageBox.Save:
                    return

        for item in self.items.values():
            value = item.value()
            if isinstance(value, str):
                value = value.strip()
            self.record.setValue(item.field(), value)

        if not self.usedFields:
            if self.model.isExist(self.record):
                result = QMessageBox.warning(
                    self, self.tr("Save"),
                    self.tr("Similar coin already exists. Save?"),
                    QMessageBox.Save | QMessageBox.No, QMessageBox.No)
                if result != QMessageBox.Save:
                    return

        self.accept()
예제 #11
0
    def _setRecord(self, record, row):
        for dstColumn, srcColumn in self.Columns.items():
            if srcColumn and srcColumn in row.keys():
                rawData = row.get(srcColumn)
                if isinstance(self.fields[srcColumn], Reference):
                    ref = self.fields[srcColumn]
                    value = ref[rawData]
                elif self.fields[srcColumn] == 'date':
                    value = QtCore.QDate.fromString(rawData, 'yyyyMMdd')
                elif srcColumn in ['COST', 'SELLPRISE']:
                    try:
                        value = stringToMoney(rawData)
                    except ValueError:
                        value = None
                else:
                    value = rawData

                record.setValue(dstColumn, value)

            if dstColumn == 'status':
                # Process Status fields that contain translated text
                value = record.value(dstColumn) or ''
                if value.lower() in ['имеется', 'приобретена', 'есть', 'в наличии']:
                    record.setValue(dstColumn, 'owned')
                elif value.lower() in ['нужна', 'нуждаюсь']:
                    record.setValue(dstColumn, 'wish')
                else:
                    record.setValue(dstColumn, 'demo')

                if row.get('SELLPRISE') or row.get('PURCHTO_CODE'):
                    record.setValue(dstColumn, 'sold')
                elif row.get('COST') or row.get('PURCHFROM_CODE'):
                    record.setValue(dstColumn, 'owned')

            if dstColumn == 'mintmark':
                mintId = row.get("MINT_CODE")
                if mintId:
                    ref = self.fields["MINT_CODE"]
                    mark = ref.mark(mintId)
                    record.setValue(dstColumn, mark)

            if dstColumn == 'catalognum1':
                catalogParts = []
                ref = self.fields["CATALOG_CODE"]
                catalog = ref[row.get("CATALOG_CODE")]
                if catalog:
                    catalogParts.append(catalog)
                catalogNum = row.get("CATALOG_NUMBER")
                if catalogNum:
                    catalogParts.append(catalogNum)
                record.setValue(dstColumn, ' '.join(catalogParts))

            imgFields = ['obverseimg', 'reverseimg', 'photo1', 'photo2']
            if dstColumn in imgFields:
                ref = self.fields["PICTURES"]
                pictures = ref[row.get("ID")]
                if pictures:
                    type_ = imgFields.index(dstColumn)
                    value = pictures[type_]
                    if value:
                        image = QtGui.QImage()
                        image.loadFromData(value)
                        record.setValue(dstColumn, image)

            if dstColumn == 'features':
                features = []
                value = row.get('NOTE')
                if value:
                    features.append(value)
                value = row.get('CERTIFIEDBY')
                if value:
                    features.append(self.tr("Certified by: %s") % value)
                value = row.get('VALUENOTE')
                if value:
                    features.append(self.tr("Price note: %s") % value)

                if features:
                    record.setValue(dstColumn, '\n'.join(features))
예제 #12
0
    def _setRecord(self, record, row):
        #put these fields is ON's note field
        featuresFields = [ 'replica', 'set', 'security', 'gradenote', 'grader', 'gradecasual', 'Authenticator', 'obversesample', 'reversesample', 'edgesample', 'displaysample', 'display2sample', 'detailsample', 'detail2sample', 'detail3', 'detail3sample', 'valuedate', 'valuesource', 'gift', 'conserved', 'restricted', 'currency', 'ebay', 'atributor', 'needsupdate', 'yearalt', 'soldfor' ]

        for dstColumn, srcColumn in self.Columns.items():
            #
            # assumed field values
            #
            if dstColumn == 'shape':
                if row.find("./t:currency", namespaces={'t': 'http://periapsis.org/tellico/'}) is None:
                    value = 'Round' #good for most coins
                else:
                    value = None
                record.setValue(dstColumn, value)
            elif dstColumn == 'obvrev':
                if row.find("./t:currency", namespaces={'t': 'http://periapsis.org/tellico/'}) is None:
                    value = 'Coin (180' + u'\u00b0' + ')' # good for US coins +
                else:
                    value = None
                record.setValue(dstColumn, value)
                    
            if srcColumn is not None:

            #############################
            #
            # multiple source processing
            #
            #############################
                #
                # Emission of production
                #
                if dstColumn == 'dateemis':
                    if row.find("./t:rangestart/t:year", namespaces={'t': 'http://periapsis.org/tellico/'}) is not None:
                        value1 = row.find("./t:rangestart/t:year", namespaces={'t': 'http://periapsis.org/tellico/'}).text
                    else: value1 = '~'
                    if row.find("./t:rangeend/t:year", namespaces={'t': 'http://periapsis.org/tellico/'}) is not None:
                        value2 = row.find("./t:rangeend/t:year", namespaces={'t': 'http://periapsis.org/tellico/'}).text
                    else: value2 = '~'
                    if value1 != '~' or value2 != '~':
                        record.setValue(dstColumn, value1+"-"+value2)
                #
                # status of coin
                #
                elif dstColumn == 'status':
                    if row.find("./t:want", namespaces={'t': 'http://periapsis.org/tellico/'}) is not None:
                        if (row.find("./t:want", namespaces={'t': 'http://periapsis.org/tellico/'}).text) == "true":
                            value = 'wish'
                        else:
                            value = 'owned'
                    else:
                        value = 'owned'

                    if value == 'owned':
                        #I have it but am I selling it?
                        if row.find("./t:sell", namespaces={'t': 'http://periapsis.org/tellico/'}) is not None:
                            if (row.find("./t:sell", namespaces={'t': 'http://periapsis.org/tellico/'}).text) == "true":
                                value = 'sale'
                        # I have/had it.  Was it sold?
                        # the status can 'sold' wether or not sell was set. so don't use an elif below
                        if row.find("./t:sold", namespaces={'t': 'http://periapsis.org/tellico/'}) is not None:
                            rawData = row.find("./t:sold", namespaces={'t': 'http://periapsis.org/tellico/'}).text
                            value = 'sold'
                    record.setValue(dstColumn, value)
                ############################
                #
                # save comments and other fields
                #
                ############################
                elif dstColumn == 'features':
                    if row.find("t:"+'comments', namespaces={'t': 'http://periapsis.org/tellico/'}) is not None:
                        value = row.find("t:"+'comments', namespaces={'t': 'http://periapsis.org/tellico/'}).text
                        value = value + '\nADDITIONAL FIELDS:\n'
                    else:
                        value = ''
                    for featuresAdd in featuresFields:
                        if row.find("./t:" + featuresAdd, namespaces={'t': 'http://periapsis.org/tellico/'}) is not None:
                            value2 = row.find("./t:" + featuresAdd, namespaces={'t': 'http://periapsis.org/tellico/'}).text
                            value = value + featuresAdd + "=" + value2 + ';\n'
                    record.setValue(dstColumn, value)
                ############################
                #
                # single souce processing
                #
                ############################
                elif srcColumn and row.find("t:"+srcColumn, namespaces={'t': 'http://periapsis.org/tellico/'}) is not None:
                    rawData = row.find("t:"+srcColumn, namespaces={'t': 'http://periapsis.org/tellico/'}).text

                    ############################
                    #
                    # has child nodes
                    #
                    ############################
                    if srcColumn == 'countrys':
                        value = row.find("./t:countrys/t:country", namespaces={'t': 'http://periapsis.org/tellico/'}).text
                        record.setValue(dstColumn, value)

                    elif srcColumn in ['cdate', 'mdate']:
                        #extract date elements from xml
                        tsYear = int(row.find("./t:"+srcColumn+"/t:year", namespaces={'t': 'http://periapsis.org/tellico/'}).text)
                        tsMonth = int(row.find("./t:"+srcColumn+"/t:month", namespaces={'t': 'http://periapsis.org/tellico/'}).text)
                        tsDay = int(row.find("./t:"+srcColumn+"/t:day", namespaces={'t': 'http://periapsis.org/tellico/'}).text)
                        recordedDate = '{:04}{:02}{:02}'.format(tsYear, tsMonth, tsDay)

                        #if id_dates set then convert recorded times to UTC
                        if self.settings['id_dates']: #krr:todo: gotta be a better way
                            #convert local time in Tellico to UTC
                            localT = pytz.timezone(self.myTZ)
                            naive = datetime.datetime.strptime(recordedDate, "%Y%m%d")
                            local_dt = localT.localize(naive)
                            utc_dt = local_dt.astimezone (pytz.utc)

                            #Convert ISODate to QDate
                            [tsCal, tsTimeSpec] = str(utc_dt).split()
                            [tsYear, tsMonth, tsDay] = tsCal.split('-')
                            [tsTime, tsOffset] = tsTimeSpec.split('+')
                            [tsHour, tsMin, tsSec] = tsTime.split(':')
                            UTCDate = QtCore.QDateTime.fromString(tsYear + tsMonth + tsDay + tsHour + tsMin + tsSec, 'yyyyMMddHHmmss')

                            record.setValue(dstColumn,
                                            UTCDate.toString(Qt.ISODate))

                    elif rawData:
                        ############################
                        #
                        # correction to sources w/o parent
                        #
                        ############################

                        #
                        # year
                        #
                        if srcColumn == 'Year':
                            if rawData == '00-00-00':
                                value = None
                            else:
                                if row.find("./t:bc", namespaces={'t': 'http://periapsis.org/tellico/'}).text:
                                    value = 0 - int(rawData)
                        #
                        # quantity
                        #
                        elif srcColumn == 'quantity':
                            if rawData == '0':
                                value = None
                            else:
                                value = rawData
                        #
                        # money fields
                        #
                        elif srcColumn in ['cost','price', 'value']:
                            if rawData == '0':
                                value = None
                            else:
                                try:
                                    value = stringToMoney(rawData)
                                except ValueError:
                                    value = None

                        #
                        # denomination processing (value, unit)
                        #
                        elif dstColumn == 'value':
                            if len(rawData.split()) == 1:
                                if rawData in ['Tokens', 'Low', 'Medium', 'High']:
                                    value = None
                                else:
                                    value = 1
                            else:
                                value = rawData.split()[0]

                        elif dstColumn == 'unit':
                            if len(rawData.split()) == 1:
                                value = rawData
                            else:
                                value = ' '.join(rawData.split()[1:])

                        elif dstColumn == 'defect':
                            if row.find("./t:error", namespaces={'t': 'http://periapsis.org/tellico/'}) is not None:
                                rawData2 = row.find("./t:error", namespaces={'t': 'http://periapsis.org/tellico/'}).text                            
                                value = rawData + 'error=' + rawData2
                        elif dstColumn == 'mintage':
                            if rawData == '':
                                value == row.find("./t:proofs", namespaces={'t': 'http://periapsis.org/tellico/'}).text
                            else:
                                if row.find("./t:X10e", namespaces={'t': 'http://periapsis.org/tellico/'}):
                                    rawData2 = row.find("./t:X10e", namespaces={'t': 'http://periapsis.org/tellico/'}).text
                                    value = longint(rawData) * int(rawData2) * 10
                                else:
                                    value = rawData
                        else:
                            value = rawData

                        record.setValue(dstColumn, value)

        # Obverse obverseimg
        # Reverse reverseimg
        # Edge edgeimg
        #*Edge2
        #*Edge3
        #*Edge4
        # Display photo1
        # Display2 photo2
        # Detail photo3
        # Detail2 photo4
        #*Detail3

        tellicoImages = ['obverse', 'reverse',
                     'edge',
                     'display', 'display2'
                     'detail', 'detail2']

        ONimgFields = ['obverseimg', 'reverseimg', 'edgeimg',
                     'photo1', 'photo2', 'photo3', 'photo4']

        image3Suffixes = ['.png','.jpg', '.bmp', '.gif']
        image4Suffixes = ['.jpeg', '.tiff']
        imageNo = 0
        for srcImg in tellicoImages:
            if row.find("./t:"+srcImg, namespaces={'t': 'http://periapsis.org/tellico/'}) is not None:
                element = row.find("./t:"+srcImg, namespaces={'t': 'http://periapsis.org/tellico/'}).text
                if element:
                    element = urllib.parse.unquote(element)
                    image = QtGui.QImage()
                    if element[:7] == 'file://':
                        if self.settings['image_name']:
                            image = element
                        else:
                            image.load(element[7:])
                    elif element[-4:] in image3Suffixes or element[-5:] in image4Suffixes:
                        if self.unzippedName: #was unzipped so is a .tc file
                            imagePath = "file://" + self.srcDB[:-3] + "_files" + "/" + element
                        else: #rm .xml
                            imagePath = "file://" + self.srcDB[:-4] + "_files" + "/" + element
                        if not os.path.exists(imagePath[7:]): #if not in sub dir look in same dir as .tc or .xml
                            imagePath = "file://" + os.path.dirname(self.srcDB) + "/" + element
                        if self.settings['image_name']:
                            image = imagePath
                        else:
                            image.load(imagePath[7:])
                    else:
                        image.loadImageData(element)

                    record.setValue(ONimgFields[imageNo], image)

                    imageNo = imageNo + 1
예제 #13
0
    def _setRecord(self, record, row):
        # put these fields is ON's note field
        featuresFields = ['replica', 'set', 'security', 'gradenote', 'grader', 'gradecasual', 'Authenticator', 'obversesample', 'reversesample', 'edgesample', 'displaysample', 'display2sample', 'detailsample', 'detail2sample', 'detail3', 'detail3sample', 'valuedate', 'valuesource', 'gift', 'conserved', 'restricted', 'currency', 'ebay', 'atributor', 'needsupdate', 'yearalt', 'soldfor']

        for dstColumn, srcColumn in self.Columns.items():
            #
            # assumed field values
            #
            if dstColumn == 'shape':
                if row.find("./t:currency", namespaces=NAMESPACES) is None:
                    value = 'Round'  # good for most coins
                else:
                    value = None
                record.setValue(dstColumn, value)
            elif dstColumn == 'obvrev':
                if row.find("./t:currency", namespaces=NAMESPACES) is None:
                    value = 'Coin (180' + u'\u00b0' + ')'  # good for US coins +
                else:
                    value = None
                record.setValue(dstColumn, value)

            if srcColumn is not None:

            #############################
            #
            # multiple source processing
            #
            #############################
                #
                # Emission of production
                #
                if dstColumn == 'dateemis':
                    if row.find("./t:rangestart/t:year", namespaces=NAMESPACES) is not None:
                        value1 = row.find("./t:rangestart/t:year", namespaces=NAMESPACES).text
                    else:
                        value1 = '~'

                    if row.find("./t:rangeend/t:year", namespaces=NAMESPACES) is not None:
                        value2 = row.find("./t:rangeend/t:year", namespaces=NAMESPACES).text
                    else:
                        value2 = '~'

                    if value1 != '~' or value2 != '~':
                        record.setValue(dstColumn, value1+"-"+value2)
                #
                # status of coin
                #
                elif dstColumn == 'status':
                    if row.find("./t:want", namespaces=NAMESPACES) is not None:
                        if (row.find("./t:want", namespaces=NAMESPACES).text) == "true":
                            value = 'wish'
                        else:
                            value = 'owned'
                    else:
                        value = 'owned'

                    if value == 'owned':
                        # I have it but am I selling it?
                        if row.find("./t:sell", namespaces=NAMESPACES) is not None:
                            if (row.find("./t:sell", namespaces=NAMESPACES).text) == "true":
                                value = 'sale'
                        # I have/had it.  Was it sold?
                        # the status can 'sold' wether or not sell was set. so don't use an elif below
                        if row.find("./t:sold", namespaces=NAMESPACES) is not None:
                            rawData = row.find("./t:sold", namespaces=NAMESPACES).text
                            value = 'sold'
                    record.setValue(dstColumn, value)
                ############################
                #
                # save comments and other fields
                #
                ############################
                elif dstColumn == 'features':
                    if row.find("t:"+'comments', namespaces=NAMESPACES) is not None:
                        value = row.find("t:"+'comments', namespaces=NAMESPACES).text
                        value = value + '\nADDITIONAL FIELDS:\n'
                    else:
                        value = ''
                    for featuresAdd in featuresFields:
                        if row.find("./t:" + featuresAdd, namespaces=NAMESPACES) is not None:
                            value2 = row.find("./t:" + featuresAdd, namespaces=NAMESPACES).text
                            value = value + featuresAdd + "=" + value2 + ';\n'
                    record.setValue(dstColumn, value)
                ############################
                #
                # single souce processing
                #
                ############################
                elif srcColumn and row.find("t:"+srcColumn, namespaces=NAMESPACES) is not None:
                    rawData = row.find("t:"+srcColumn, namespaces=NAMESPACES).text

                    ############################
                    #
                    # has child nodes
                    #
                    ############################
                    if srcColumn == 'countrys':
                        value = row.find("./t:countrys/t:country", namespaces=NAMESPACES).text
                        record.setValue(dstColumn, value)

                    elif rawData:
                        ############################
                        #
                        # correction to sources w/o parent
                        #
                        ############################

                        #
                        # year
                        #
                        if srcColumn == 'Year':
                            if rawData == '00-00-00':
                                value = None
                            else:
                                if row.find("./t:bc", namespaces=NAMESPACES).text:
                                    value = 0 - int(rawData)
                        #
                        # quantity
                        #
                        elif srcColumn == 'quantity':
                            if rawData == '0':
                                value = None
                            else:
                                value = rawData
                        #
                        # money fields
                        #
                        elif srcColumn in ['cost', 'price', 'value']:
                            if rawData == '0':
                                value = None
                            else:
                                try:
                                    value = stringToMoney(rawData)
                                except ValueError:
                                    value = None

                        #
                        # denomination processing (value, unit)
                        #
                        elif dstColumn == 'value':
                            if len(rawData.split()) == 1:
                                if rawData in ['Tokens', 'Low', 'Medium', 'High']:
                                    value = None
                                else:
                                    value = 1
                            else:
                                value = rawData.split()[0]

                        elif dstColumn == 'unit':
                            if len(rawData.split()) == 1:
                                value = rawData
                            else:
                                value = ' '.join(rawData.split()[1:])

                        elif dstColumn == 'defect':
                            if row.find("./t:error", namespaces=NAMESPACES) is not None:
                                rawData2 = row.find("./t:error", namespaces=NAMESPACES).text                            
                                value = rawData + 'error=' + rawData2
                        elif dstColumn == 'mintage':
                            if rawData == '':
                                value == row.find("./t:proofs", namespaces=NAMESPACES).text
                            else:
                                if row.find("./t:X10e", namespaces=NAMESPACES):
                                    rawData2 = row.find("./t:X10e", namespaces=NAMESPACES).text
                                    value = int(rawData) * int(rawData2) * 10
                                else:
                                    value = rawData
                        else:
                            value = rawData

                        record.setValue(dstColumn, value)

        # Obverse obverseimg
        # Reverse reverseimg
        # Edge edgeimg
        #*Edge2
        #*Edge3
        #*Edge4
        # Display photo1
        # Display2 photo2
        # Detail photo3
        # Detail2 photo4
        #*Detail3

        tellicoImages = ['obverse', 'reverse',
                    'edge',
                    'display', 'display2'
                    'detail', 'detail2']

        ONimgFields = ['obverseimg', 'reverseimg', 'edgeimg',
                    'photo1', 'photo2', 'photo3', 'photo4']

        imageSuffixes = ['.png', '.jpg', '.bmp', '.gif', '.jpeg', '.tiff']
        imageNo = 0
        for srcImg in tellicoImages:
            if row.find("./t:"+srcImg, namespaces=NAMESPACES) is not None:
                element = row.find("./t:"+srcImg, namespaces=NAMESPACES).text
                if element:
                    element = urllib.parse.unquote(element)
                    extension = os.path.splitext(element)[1]
                    image = QtGui.QImage()
                    if element[:7] == 'file://':
                        image.load(element[7:])
                    elif extension in imageSuffixes:
                        imagePath = os.path.join(self.unzippedDir, 'images', element)

                        if not os.path.exists(imagePath):  # if not in sub dir look in same dir as .tc
                            imagePath = os.path.join(self.unzippedDir, element)

                        image.load(imagePath)
                    else:
                        image.loadImageData(element)

                    record.setValue(ONimgFields[imageNo], image)

                imageNo = imageNo + 1
예제 #14
0
    def _setRecord(self, record, row):
        for dstColumn, srcColumn in self.Columns.items():
            if srcColumn and row.find(srcColumn) is not None:
                rawData = row.find(srcColumn).text
                if rawData:
                    if srcColumn == 'Income':
                        value = QtCore.QDate.fromString(rawData, 'ddMMyyyy')
                    elif srcColumn == 'Year' and rawData == 'N/A':
                        value = None
                    elif srcColumn in [
                            'Nominal', 'Diameter', 'Thickness',
                            'ReversRotation', 'Weight'
                    ]:
                        if rawData == '0':
                            value = None
                        else:
                            value = rawData
                    elif srcColumn == 'Duplicates':
                        if rawData == '0':
                            value = None
                        else:
                            value = int(rawData) + 1
                    elif srcColumn in ['Price', 'CatalogPrice']:
                        if rawData == '0':
                            value = None
                        else:
                            try:
                                value = stringToMoney(rawData)
                            except ValueError:
                                value = None
                    else:
                        value = rawData

                    record.setValue(dstColumn, value)

            if dstColumn == 'status':
                value = 'owned'
                # Process Status fields that contain translated text
                element = row.find('ItemStatus').find('Status')
                if element.text in ['Private', 'Частный', 'Прыватны']:
                    value = 'demo'
                elif element.text in ['Lost', 'Утерян', 'Згублен']:
                    value = 'wish'
                elif element.text in ['Sold', 'Продан', 'Прададзен']:
                    value = 'sold'

                record.setValue(dstColumn, value)

        imgFields = [
            'obverseimg', 'reverseimg', 'photo1', 'photo2', 'photo3', 'photo4'
        ]
        imageNo = 0
        imageElements = row.find('Images')
        if imageElements is not None:
            for element in imageElements.iter('Data'):
                if element.text:
                    value = base64.b64decode(bytes(element.text, 'latin-1'))
                    image = QtGui.QImage()
                    image.loadFromData(value)
                    record.setValue(imgFields[imageNo], image)
                    imageNo = imageNo + 1

        record.setValue('title', self.__generateTitle(record))