コード例 #1
0
ファイル: qobject.py プロジェクト: Astonyang/ticket
 def __new__(cls, cls_name, cls_bases, cls_dict):
     super_new = super(QPropertyMeta, cls).__new__
     props = cls_dict.get("__qtprops__", None)
     if props is not None:
         for key, values in six.iteritems(props):
             nty = cls_dict['_nty_'+key] = QtCore.pyqtSignal()
             if isinstance(values, tuple) and len(values) == 2:
                 _type, default = values
             else:    
                 _type = type(values)
                 if _type not in (int, str, bool):
                     _type = "QVariant"
                 default = values
                 
             cls_dict["_"+key] = default
             
             def _get(key):
                 def f(self):
                     return getattr(self, '_'+key)
                 return f
             
             def _set(key):
                 def f(self, value):
                     setattr(self, '_'+key, value)
                     getattr(self, "_nty_"+key).emit()                    
                 return f
             
             set_func = cls_dict['_set_'+key] = _set(key)
             get_func = cls_dict['_get_'+key] = _get(key)
             
             cls_dict[key] = QtCore.pyqtProperty(_type, get_func, set_func, notify=nty)
     return super_new(cls, cls_name, cls_bases, cls_dict)        
コード例 #2
0
ファイル: qobject.py プロジェクト: zhangjingpu/ticket
    def data(self, index, role):
        if not index.isValid() or index.row() > self.size():
            return QtCore.QVariant()
        try:
            item = self._data[index.row()]
        except:
            return QtCore.QVariant()

        for r, name in six.iteritems(self._roles):
            if r == role:
                getattr(item, name, QtCore.QVariant())
        return QtCore.QVariant()
コード例 #3
0
ファイル: qobject.py プロジェクト: Astonyang/ticket
 def data(self, index, role):
     if not index.isValid() or index.row() > self.size():
         return QtCore.QVariant()
     try:
         item = self._data[index.row()]
     except:
         return QtCore.QVariant()
     
     for r, name in six.iteritems(self._roles):
         if r == role:
             getattr(item, name, QtCore.QVariant())
     return QtCore.QVariant()        
コード例 #4
0
 def _convert_from_unicode(data):
     new_data = dict()
     for name, value in six.iteritems(data):
         if isinstance(name, six.string_types):
             name = unicodedata.normalize('NFKD', name).encode(
                 'ascii', 'ignore')
         if isinstance(value, six.string_types):
             value = unicodedata.normalize('NFKD', value).encode(
                 'ascii', 'ignore')
         if isinstance(value, dict):
             value = _convert_from_unicode(value)
         new_data[name] = value
     return new_data
コード例 #5
0
ファイル: models.py プロジェクト: zach14c/ticket
 def parseQuery(cls, queryItem):    
     result = {}
     seats = []
     for k, v in six.iteritems(queryItem):
         nk = stringTitle(k)
         if k in JSON_SEAT and v != "--":
             try: numValue = int(v)
             except: numValue = 0    
             seat = dict(name=JSON_SEAT[k], num=numValue)                
             seats.append(ObjectWrapper(seat))
         else:    
             result[nk] = v
     seats = sorted(seats, key=lambda item: cls.SeatSorted.index(item.name))        
     result['seats'] = seats
     result['fromStationType'] = cls.getFromStationType(result)
     result['toStationType'] = cls.getToStationType(result)
     result['lishi'] = cls.parseLishiValue(result['lishiValue'])
     result['buttonTextInfo'] = result['note'].replace("<br/>", '    ')
     result['canBuy'] = "br" not in result['note']
     return result
コード例 #6
0
ファイル: models.py プロジェクト: zhangjingpu/ticket
 def parseQuery(cls, queryItem):
     result = {}
     seats = []
     for k, v in six.iteritems(queryItem):
         nk = stringTitle(k)
         if k in JSON_SEAT and v != "--":
             try:
                 numValue = int(v)
             except:
                 numValue = 0
             seat = dict(name=JSON_SEAT[k], num=numValue)
             seats.append(ObjectWrapper(seat))
         else:
             result[nk] = v
     seats = sorted(seats, key=lambda item: cls.SeatSorted.index(item.name))
     result['seats'] = seats
     result['fromStationType'] = cls.getFromStationType(result)
     result['toStationType'] = cls.getToStationType(result)
     result['lishi'] = cls.parseLishiValue(result['lishiValue'])
     result['buttonTextInfo'] = result['note'].replace("<br/>", '    ')
     result['canBuy'] = "br" not in result['note']
     return result
コード例 #7
0
ファイル: models.py プロジェクト: zach14c/ticket
 def parseTicketQuery(cls, queryItem):
     result = {}
     seats = []
     queryLeftNewDTO = queryItem.pop("queryLeftNewDTO", {})
     result['buttonTextInfo'] = queryItem.pop("buttonTextInfo", "")
     result['secretStr'] = queryItem.pop("secretStr", "")
     for k, v in six.iteritems(queryLeftNewDTO):
         nk = stringTitle(k)
         if k in JSON_SEAT and v != "--":
             if v == "无": v = 0
             seat = dict(name=JSON_SEAT[k], num=v)                
             seats.append(ObjectWrapper(seat))
         else:    
             result[nk] = v
     seats = sorted(seats, key=lambda item: cls.SeatSorted.index(item.name))        
     result['seats'] = seats
     result['fromStationType'] = cls.getFromStationType(result)
     result['toStationType'] = cls.getToStationType(result)
     result['lishi'] = cls.parseLishiValue(result['lishiValue'])
     result['canBuy'] = "br" not in result['buttonTextInfo']
     result['buttonTextInfo'] = result['buttonTextInfo'].replace("<br/>", '    ')
     return result
コード例 #8
0
ファイル: models.py プロジェクト: zhangjingpu/ticket
 def parseTicketQuery(cls, queryItem):
     result = {}
     seats = []
     queryLeftNewDTO = queryItem.pop("queryLeftNewDTO", {})
     result['buttonTextInfo'] = queryItem.pop("buttonTextInfo", "")
     result['secretStr'] = queryItem.pop("secretStr", "")
     for k, v in six.iteritems(queryLeftNewDTO):
         nk = stringTitle(k)
         if k in JSON_SEAT and v != "--":
             if v == "无": v = 0
             seat = dict(name=JSON_SEAT[k], num=v)
             seats.append(ObjectWrapper(seat))
         else:
             result[nk] = v
     seats = sorted(seats, key=lambda item: cls.SeatSorted.index(item.name))
     result['seats'] = seats
     result['fromStationType'] = cls.getFromStationType(result)
     result['toStationType'] = cls.getToStationType(result)
     result['lishi'] = cls.parseLishiValue(result['lishiValue'])
     result['canBuy'] = "br" not in result['buttonTextInfo']
     result['buttonTextInfo'] = result['buttonTextInfo'].replace(
         "<br/>", '    ')
     return result
コード例 #9
0
ファイル: qobject.py プロジェクト: zhangjingpu/ticket
    def __new__(cls, cls_name, cls_bases, cls_dict):
        super_new = super(QPropertyMeta, cls).__new__
        props = cls_dict.get("__qtprops__", None)
        if props is not None:
            for key, values in six.iteritems(props):
                nty = cls_dict['_nty_' + key] = QtCore.pyqtSignal()
                if isinstance(values, tuple) and len(values) == 2:
                    _type, default = values
                else:
                    _type = type(values)
                    if _type not in (int, str, bool):
                        _type = "QVariant"
                    default = values

                cls_dict["_" + key] = default

                def _get(key):
                    def f(self):
                        return getattr(self, '_' + key)

                    return f

                def _set(key):
                    def f(self, value):
                        setattr(self, '_' + key, value)
                        getattr(self, "_nty_" + key).emit()

                    return f

                set_func = cls_dict['_set_' + key] = _set(key)
                get_func = cls_dict['_get_' + key] = _get(key)

                cls_dict[key] = QtCore.pyqtProperty(_type,
                                                    get_func,
                                                    set_func,
                                                    notify=nty)
        return super_new(cls, cls_name, cls_bases, cls_dict)
コード例 #10
0
def write_dictionary_to_file(input_dict, filename, sortkeys=False):
    # ensure dir
    d = os.path.dirname(filename)
    if not os.path.exists(d):
        os.makedirs(d)

    item_iterator = six.itersorteditems(input_dict) if sortkeys else six.iteritems(input_dict)

    # check for json extension
    ext = os.path.splitext(filename)[1]
    if ext == ".json":
        with open(filename, 'w') as file:
            file.write("{\n")
            for i, (key, value) in enumerate(item_iterator):
                file.write("  \"%s\": %s" % (key, _parse_value(value)))
                if i < len(input_dict) - 1:
                    file.write(',\n')
                else:
                    file.write('\n')
            file.write("}\n")
    else:
        with open(filename, 'w') as file:
            for key, value in item_iterator:
                file.write('%s: %s\n' % (key, value))
コード例 #11
0
ファイル: poster.py プロジェクト: zach14c/ticket
JSON_SEAT = {
    "gr_num" : "高级软卧",
    "qt_num" : "其他",
    "rw_num" : "软卧",
    "rz_num" : "软座",
    "tz_num" : "特等座",
    "wz_num" : "无座",
    "yw_num" : "硬卧",
    "yz_num" : "硬座",
    "ze_num" : "二等座",
    "zy_num" : "一等座",
    "swz_num" : "商务座",
}

REVERSAL_JSON_SEAT = dict((v, k) for k,v in six.iteritems(JSON_SEAT))

class Poster(object):
    
    def __init__(self, username=None, passwd=None):
        self._username = username
        self._passwd = passwd
        
        self._headers = {
            "User-Agent" : "Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; Trident/5.0;)",
        }
        cookie_jar = cookielib.LWPCookieJar()        
        self._session = requests.Session()        
        self._session.cookies = cookie_jar
        self._session.headers = self._headers
        self._session.verify = False
コード例 #12
0
ファイル: models.py プロジェクト: zhangjingpu/ticket
 def initSeats(self):
     for k, v in six.iteritems(SEAT_TYPE):
         seat = dict(seatName=k, seatType=v)
         self.append(ObjectWrapper(seat))
コード例 #13
0
ファイル: models.py プロジェクト: zhangjingpu/ticket
def peeweeWrapper(instance):
    params = instance.__dict__['_data']
    ret = {}
    for k, v in six.iteritems(params):
        ret[stringTitle(k)] = v
    return ObjectWrapper(ret)
コード例 #14
0
ファイル: models.py プロジェクト: zach14c/ticket
 def initSeats(self):    
     for k, v in six.iteritems(SEAT_TYPE):
         seat = dict(seatName=k, seatType=v)
         self.append(ObjectWrapper(seat))
コード例 #15
0
ファイル: models.py プロジェクト: zach14c/ticket
def peeweeWrapper(instance):
    params = instance.__dict__['_data']
    ret = {}
    for k, v in six.iteritems(params):
        ret[stringTitle(k)] = v
    return ObjectWrapper(ret)
コード例 #16
0
JSON_SEAT = {
    "gr_num" : "高级软卧",
    "qt_num" : "其他",
    "rw_num" : "软卧",
    "rz_num" : "软座",
    "tz_num" : "特等座",
    "wz_num" : "无座",
    "yw_num" : "硬卧",
    "yz_num" : "硬座",
    "ze_num" : "二等座",
    "zy_num" : "一等座",
    "swz_num" : "商务座",
}

REVERSAL_JSON_SEAT = dict((v, k) for k,v in six.iteritems(JSON_SEAT))

class Poster(object):
    
    def __init__(self, username=None, passwd=None):
        self._username = username
        self._passwd = passwd
        
        self._headers = {
            "User-Agent" : "Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; Trident/5.0;)",
        }
        cookie_jar = cookielib.LWPCookieJar()        
        self._session = requests.Session()        
        self._session.cookies = cookie_jar
        self._session.headers = self._headers
        self._session.verify = False