示例#1
0
    def __updateInfo(self, initial=False):
        if not initial:
            self.user = foursquare.get_user("self", foursquare.CacheOrGet)['user']
        if self.manualUpdate:
            QMaemo5InformationBox.information(self, "Stats updated!", 1500)
            self.manualUpdate = False

        badges = "<b>" + str(self.user['badges']['count']) + "</b> badges"
        mayorships = "<b>" + str(self.user['mayorships']['count']) + "</b> mayorships"
        checkins = "<b>" + str(self.user['checkins']['count']) + "</b> checkins"

        if 'items' in self.user['checkins']:
            location = self.user['checkins']['items'][0]['venue']['name']
            lastSeen = self.user['checkins']['items'][0]['createdAt']
            lastSeen = datetime.fromtimestamp(lastSeen).strftime("%Y-%m-%d %X")
            location = "Last seen @" + location # + "</b>, at <i>" + lastSeen + "</i>"
        else:
            location = "Never checked in anywhere!"


        text = location + "<br>" + badges + " | " + mayorships + " | " + checkins
        self.textLabel.setText(text)

        self.photo = QImage(foursquare.image(self.user['photo']))
        self.photo_label.setPixmap(QPixmap(self.photo))
示例#2
0
    def __init__(self, parent=None):
        super(Profile, self).__init__(parent)
        self.manualUpdate = False
        self.user = foursquare.get_user("self", foursquare.Cache.CacheOrGet)['user']
        self.photo_label = QLabel()

        self.textLabel = QLabel()
        self.textLabel.setWordWrap(True)
        self.__updateInfo(True)

        name = ""
        if 'firstName' in self.user:
            name += self.user['firstName'] + " "
        if 'lastName' in self.user:
            name += self.user['lastName']

        self.nameTitle = Title(name)

        profileLayout = QGridLayout()
        self.setLayout(profileLayout)
        profileLayout.addWidget(self.photo_label, 0, 0, 2, 1)
        profileLayout.addWidget(self.nameTitle, 0, 1)
        profileLayout.addWidget(self.textLabel, 1, 1)
        profileLayout.setColumnStretch(1, 5)
        profileLayout.setSpacing(5)
        profileLayout.setContentsMargins(11, 11, 11, 11)

        clicked = Signal()
        self.connect(self, SIGNAL("clicked()"), self.__clicked)

        selfUpdated = Signal()
        self.connect(self, SIGNAL("selfUpdated()"), self.__updateInfo)

        foursquare.add_checkin_hook(self.checkin)
示例#3
0
 def __showUser(self):
     time.sleep(0.15)
     self.close()
     self.uid = self.user['user']['id']
     user = foursquare.get_user(self.uid, foursquare.CacheOrNull)
     if user:
         self.userWindow = UserDetailsWindow(user, self)
         self.userWindow.show()
示例#4
0
    def user_selected(self, index):
        self.uid = self.list.getUser(index)['user']['id']
        user = foursquare.get_user(self.uid, foursquare.CacheOrNull)

        if user:
            self.userWindow = UserDetailsWindow(user, self)
            self.userWindow.show()
        else:
            t = UserDetailsThread(self.uid, self)
            t.start()
示例#5
0
 def run(self):
     try:
         user = foursquare.get_user(self.userId, foursquare.ForceFetch)
         photo = user['user']['photo']
         foursquare.image(photo)
         self.__parent.hideWaitingDialog.emit()
         self.__parent.showUser.emit()
     except IOError:
         self.__parent.hideWaitingDialog.emit()
         self.__parent.networkError.emit()
     self.exec_()
     self.exit(0)
示例#6
0
def start():
    app = QApplication(sys.argv)

    token_present = foursquare.config_get("access_token") != None

    if not token_present:
        msgBox = QMessageBox()
        msgBox.setText("Hi! It looks like this is the first run!\n\nI'm going to open a browser window now, and I need you to authorize me so I can get data/do your check-ins, etc.")
        msgBox.setWindowTitle("First run")
        msgBox.addButton("Ok", QMessageBox.AcceptRole)
        msgBox.addButton("Cancel", QMessageBox.RejectRole)
        msgBox.exec_()
        if msgBox.buttonRole(msgBox.clickedButton()) == QMessageBox.AcceptRole:
            foursquare_auth.fetch_code()
            foursquare_auth.fetch_token()
            token_present = True
            d = QMessageBox()
            d.setWindowTitle("Image cache")
            d.setText("In order to save bandwidth, category images are cached.  To download these images for a first time, click \"Update image cache\". This'll take some time, but will <b>really</b> speed up searches.")
            d.addButton("Ok", QMessageBox.YesRole)
            d.exec_()

    if token_present:
        try:
            foursquare.get_user("self", foursquare.CacheOrGet)
        except IOError:
            d = QMessageBox()
            d.setWindowTitle("Network Error")
            d.setText("I couldn't connect to foursquare to retrieve data. Make sure yo're connected to the internet, and try again (keep in mind that it may have been just a network glitch).")
            d.addButton("Ok", QMessageBox.YesRole)
            d.exec_()

        main_window = MainWindow()
        main_window.show()

    sys.exit(app.exec_())
示例#7
0
 def run(self):
     try:
         foursquare.get_user("self", foursquare.ForceFetch)
         self.__parent.selfUpdated.emit()
     except IOError:
         self.__parent.networkError.emit()
示例#8
0
 def __showUser(self):
     user = foursquare.get_user(self.uid, foursquare.CacheOrNull)
     self.userWindow = UserDetailsWindow(user, self)
     self.userWindow.show()