Exemple #1
0
    def __init__(self, parent=None, session=None, token=None):
        super().__init__(parent, Qt.Window)
        self.sizeMonitor = QApplication.desktop().availableGeometry()
        self.setGeometry(self.sizeMonitor.width() / 6, 0,
                         (2 * self.sizeMonitor.width()) / 3,
                         self.sizeMonitor.height())

        myForm = QFormLayout()

        # Create scroll and put in general layout
        scrollWidget = QWidget()
        scrollWidget.setLayout(myForm)
        scroll = QScrollArea()
        scroll.setWidget(scrollWidget)
        scroll.setWidgetResizable(True)
        layout = QVBoxLayout(self)
        layout.addWidget(scroll)

        downloader = DownloadDecorator(session)
        api = API(session, token)

        groups = api.groups.get(extended=1)
        for group in groups['response']['items']:
            downloader(group["photo_100"], 'None', 'group', group['name'],
                       group['id'])

        download = downloader.download()
        for item in download:
            g = Group(session=session, token=token)
            g.setGroup(item[0].content, item[3][0], item[3][1])
            myForm.addWidget(g)

        self.show()
Exemple #2
0
    def __init__(self, parent=None, session=None, token=None):
        super().__init__(parent, Qt.Window)
        self.ui()

        self.session = session
        self.token = token
        self.currentPhoto = 0
        self.downloadDecorator = DownloadDecorator(self.session)
        self.methodHandler = MethodHandler(self.session, self.token)
        self.createApi = UrlAPI(self.token)
        self.pixmap = QtGui.QPixmap()
        self.curCountRecords = 10

        self.btn_save.clicked.connect(self.save)
        self.btn_photo.clicked.connect(lambda: PhotosForm(
            self, self.session, self.token, self.dataAllPhotos))
        self.btn_friends.clicked.connect(
            lambda: FriendsForm(self, self.session, self.token))
        self.avatarImg.clicked.connect(
            lambda: ChangeAvatar(self, self.session, self.token))
        self.btn_addRecord.clicked.connect(
            lambda: AddPost(self, self.session, self.token))
        self.btn_addPhoto.clicked.connect(
            lambda: AddPhoto(self, self.session, self.token))
        self.btn_groups.clicked.connect(
            lambda: GroupForm(self, self.session, self.token))
        self.btn_load_more_records.clicked.connect(self.loadMoreRecords)
        self.btn_add_group.clicked.connect(lambda: print('add Group'))
        self.btn_setting_privacy.clicked.connect(self.settingPrivacy)
        self.btn_clearingGroups.clicked.connect(self.clearingGroups)

        self.quit = QShortcut(QKeySequence(Qt.Key_Escape), self)
        self.quit.activated.connect(self.close)

        try:
            self.getMainInform()
            self.getSecondInform()
        except KeyError:
            print('Ошибка загрузки данных')

        self.show()
Exemple #3
0
    def __init__(self, parent=None, session=None, token=None):
        super().__init__(parent, Qt.Window)
        self.downloader = DownloadDecorator(session)
        self.session = session
        getUrl = UrlAPI(token)

        # choise photos
        path = QFileDialog.getOpenFileName()
        self.session.headers.update(Accept='multipart/form-data')

        # get upload url for photos
        urlUpload = getUrl.photos.getOwnerPhotoUploadServer()
        response = self.session.get(urlUpload, proxies=self.session.proxies)
        j1 = json.loads(response.text)
        urlUpload = j1['response']['upload_url']
        print(response.text)

        try:
            r = self.session.post(urlUpload,
                                  files={'photo': open(path[0], 'rb')},
                                  proxies=self.session.proxies)
        except FileNotFoundError:
            return print('Не был выбран файл')

        dataUU = json.loads(r.text)
        print(r.text)

        server = dataUU['server']
        photo = dataUU['photo']
        hash = dataUU['hash']
        saveUrl = getUrl.photos.saveOwnerPhoto(server=server,
                                               photo=photo,
                                               hash=hash)
        r = self.session.get(saveUrl, proxies=self.session.proxies)
        print(r.text)

        res = json.loads(r.text)
        if 'saved' in res['response']:
            print('Upload avatar completed')
Exemple #4
0
    def filing(self):
        downloader = DownloadDecorator(self.session)
        urlAlbums = self.createApi.photos.getAlbums(need_system=1)
        downloader(urlAlbums, 'None', 'albums')

        for item in self.dataAllPhotos['items']:
            value = datetime.datetime.fromtimestamp(item['date'])
            urlPhoto = item['photo_604']
            downloader(urlPhoto, value.year, 'photos', item['id'])

        download = downloader.download()
        groupYear = [[0, 0]]

        for item in download:

            if item[2] == 'photos':
                photo = Photo(self, item[0], item[3][0], self.api)
                year = item[1]
                yearWidget = QWidget()
                yearLayout = QHBoxLayout()

                b = False
                for mas in groupYear:
                    if year in mas:
                        yearLayout = mas[1]
                        yearLayout.addWidget(photo, alignment=Qt.AlignLeft)
                        yearWidget = mas[2]

                        self.updateWidgetSize(yearWidget, yearLayout)
                        b = True

                        break

                if b == False:
                    yearLayout = QHBoxLayout()
                    yearLayout.addWidget(photo, alignment=Qt.AlignLeft)
                    yearWidget = QWidget()
                    yearWidget.setLayout(yearLayout)
                    labelYear = QLabel(str(year))

                    self.mainLayout.addWidget(labelYear,
                                              alignment=Qt.AlignLeft)
                    self.mainLayout.addWidget(yearWidget,
                                              alignment=Qt.AlignLeft)
                    self.updateWidgetSize(yearWidget, yearLayout)

                    groupYear.append([year, yearLayout, yearWidget])

                photo.clicked.connect(
                    lambda: self.updateWidgetSize(yearWidget, yearLayout))

            if item[2] == 'albums':
                data = json.loads(item[0].text)

                for album in data['response']['items']:
                    albumWidget = ItemAlbum(title=album['title'],
                                            size=album['size'],
                                            id=album['id'],
                                            api=self.api)

                    self.albumLayout.addWidget(albumWidget)
                    self.albumWidget.setFixedWidth(
                        self.albumLayout.totalSizeHint().width())
                    self.albumWidget.setFixedHeight(
                        self.albumLayout.totalSizeHint().height())
Exemple #5
0
    def loadMoreRecords(self):
        downloader = DownloadDecorator(self.session)
        offset = self.curCountRecords + 1
        self.curCountRecords = self.curCountRecords + 50

        url = self.createApi.wall.get(extended=1, count=50, offset=offset)
        response = requests.get(url, proxies=self.session.proxies)
        self.dataWall = json.loads(response.text)['response']

        # mark reckords wall
        for i in range(len(self.dataWall['items'])):
            record = RecordWall(session=self.session, token=self.token)

            # Set post ID
            record.post_id = self.dataWall['items'][i]['id']

            # Set name
            if self.dataWall['items'][i]['from_id'] == self.dataWall['items'][
                    i]['owner_id']:
                record.setNameLayout('Я', '.', 'src/icon.png')
            else:

                record.setNameLayout(str(self.dataWall['items'][i]['from_id']),
                                     '.', 'src/icon.png')

            # Post source
            if 'data' in self.dataWall['items'][i]['post_source']:
                record.setPostSource(
                    self.dataWall['items'][i]['post_source']['data'])

            # Set data
            record.setDateLayout(self.dataWall['items'][i]['date'])

            # Set text
            record.setText(self.dataWall['items'][i]['text'])

            # Attechments
            if 'attachments' in self.dataWall['items'][i]:
                for item in self.dataWall['items'][i]['attachments']:
                    if item['type'] == 'photo':
                        downloader(item['photo']['photo_130'],
                                   record.setAttachments, 'wallAtt')

            # Information
            if 'views' in self.dataWall['items'][i]:
                record.setInfo(self.dataWall['items'][i]['likes']['count'],
                               self.dataWall['items'][i]['reposts']['count'],
                               self.dataWall['items'][i]['views']['count'])
            else:
                record.setInfo(self.dataWall['items'][i]['likes']['count'],
                               self.dataWall['items'][i]['reposts']['count'])

            # Repost
            if 'copy_history' in self.dataWall['items'][i]:
                repost = RecordWall()
                repost.deleteInformation()
                repost.delButton.deleteLater()
                repost.frame.setFrameShape(QFrame.StyledPanel)

                repost.setText(
                    self.dataWall['items'][i]['copy_history'][0]['text'])
                repost.setDateLayout(
                    self.dataWall['items'][i]['copy_history'][0]['date'])
                '''Set attachments'''
                if 'attachments' in self.dataWall['items'][i]['copy_history'][
                        0]:
                    for item in self.dataWall['items'][i]['copy_history']:
                        for ite in item['attachments']:
                            if ite['type'] == 'photo':
                                downloader(ite['photo']['photo_604'],
                                           repost.setAttachments, 'wallAtt')
                '''Set profile info'''
                for item in self.dataWall['items'][i]['copy_history']:
                    owner_id = item['owner_id']
                    if owner_id < 0:
                        for group in self.dataWall['groups']:
                            if group['id'] == (owner_id * -1):
                                downloader(group['photo_50'],
                                           repost.setNameLayout, 'wallAtt',
                                           group['name'], '.')

                    elif owner_id > 0:
                        for profile in self.dataWall['profiles']:
                            if profile['id'] == (owner_id):
                                downloader(profile['photo_50'],
                                           repost.setNameLayout, 'wallAtt',
                                           profile['first_name'],
                                           profile['last_name'])

                record.repostLayout.addWidget(repost)

            self.myForm.addRow(record)

        # Append btn for load more records
        self.myForm.addRow(self.btn_load_more_records)

        download = downloader.download()

        for item in download:

            if item[2] == 'wallAtt':

                if item[3] == ():
                    seter = item[1]
                    photo = item[0]
                    seter(photo.content)
                elif item[3] != ():
                    mas = []
                    for i in item[3]:
                        mas.append(i)
                    seter = item[1]
                    photo = item[0]
                    seter(*mas, photo.content)
Exemple #6
0
    def getSecondInform(self):
        downloader = DownloadDecorator(self.session)

        # mark reckords wall
        for i in range(len(self.dataWall['items'])):
            record = RecordWall(session=self.session, token=self.token)

            # Set post ID
            record.post_id = self.dataWall['items'][i]['id']

            # Set name
            if self.dataWall['items'][i]['from_id'] == self.dataWall['items'][
                    i]['owner_id']:
                record.setNameLayout('Я', '.', 'src/icon.png')
            else:

                record.setNameLayout(str(self.dataWall['items'][i]['from_id']),
                                     '.', 'src/icon.png')

            # Post source
            if 'data' in self.dataWall['items'][i]['post_source']:
                record.setPostSource(
                    self.dataWall['items'][i]['post_source']['data'])

            # Set data
            record.setDateLayout(self.dataWall['items'][i]['date'])

            # Set text
            record.setText(self.dataWall['items'][i]['text'])

            # Attechments
            if 'attachments' in self.dataWall['items'][i]:
                for item in self.dataWall['items'][i]['attachments']:
                    if item['type'] == 'photo':
                        downloader(item['photo']['photo_130'],
                                   record.setAttachments, 'wallAtt')

            # Information
            if 'views' in self.dataWall['items'][i]:
                record.setInfo(self.dataWall['items'][i]['likes']['count'],
                               self.dataWall['items'][i]['reposts']['count'],
                               self.dataWall['items'][i]['views']['count'])
            else:
                record.setInfo(self.dataWall['items'][i]['likes']['count'],
                               self.dataWall['items'][i]['reposts']['count'])

            # Repost
            if 'copy_history' in self.dataWall['items'][i]:
                repost = RecordWall()
                repost.deleteInformation()
                repost.delButton.deleteLater()
                repost.frame.setFrameShape(QFrame.StyledPanel)

                repost.setText(
                    self.dataWall['items'][i]['copy_history'][0]['text'])
                repost.setDateLayout(
                    self.dataWall['items'][i]['copy_history'][0]['date'])
                '''Set attachments'''
                if 'attachments' in self.dataWall['items'][i]['copy_history'][
                        0]:
                    for item in self.dataWall['items'][i]['copy_history']:
                        for ite in item['attachments']:
                            if ite['type'] == 'photo':
                                downloader(ite['photo']['photo_604'],
                                           repost.setAttachments, 'wallAtt')
                '''Set profile info'''
                for item in self.dataWall['items'][i]['copy_history']:
                    owner_id = item['owner_id']
                    if owner_id < 0:
                        for group in self.dataWall['groups']:
                            if group['id'] == (owner_id * -1):
                                downloader(group['photo_50'],
                                           repost.setNameLayout, 'wallAtt',
                                           group['name'], '.')

                    elif owner_id > 0:
                        for profile in self.dataWall['profiles']:
                            if profile['id'] == (owner_id):
                                downloader(profile['photo_50'],
                                           repost.setNameLayout, 'wallAtt',
                                           profile['first_name'],
                                           profile['last_name'])

                record.repostLayout.addWidget(repost)

            self.myForm.addRow(record)

        # Append btn for load more records
        self.myForm.addRow(self.btn_load_more_records)

        # mark allPhotos
        masLabelImg = [
            self.labelImg1, self.labelImg2, self.labelImg3, self.labelImg4
        ]
        for nLabelImg in range(len(masLabelImg)):
            try:
                urlPhoto = self.dataAllPhotos['items'][nLabelImg]['photo_604']
                downloader(urlPhoto, masLabelImg[nLabelImg], 'allPhotosAtt')
            except:
                pass

        # mark avatar
        masAvatar = []
        for item in self.dataAllPhotos['items']:
            if item['album_id'] == -6:
                masAvatar.append([item['photo_604'], item['id']])

        masAvatar.sort(key=lambda mas: mas[1], reverse=1)

        try:
            downloader(masAvatar[0][0], 'None', 'avatarPhoto')
        except:
            pass

        download = downloader.download()

        for item in download:

            if item[2] == 'wallAtt':
                if item[3] == ():
                    seter = item[1]
                    photo = item[0]
                    seter(photo.content)
                elif item[3] != ():
                    mas = []
                    for i in item[3]:
                        mas.append(i)
                    seter = item[1]
                    photo = item[0]
                    seter(*mas, photo.content)

            if item[2] == 'allPhotosAtt':
                photo = item[0]
                self.pixmap.loadFromData(photo.content)
                myPixmap = self.pixmap.scaled(self.labelImg1.size(),
                                              Qt.KeepAspectRatio,
                                              Qt.FastTransformation)
                labelImg = item[1]
                labelImg.setPixmap(myPixmap)

            if item[2] == 'avatarPhoto':
                photo = item[0]
                self.pixmap.loadFromData(photo.content)
                myPixmap = self.pixmap.scaled(self.avatarImg.size(),
                                              Qt.KeepAspectRatio,
                                              Qt.FastTransformation)
                self.avatarImg.setPixmap(myPixmap)
Exemple #7
0
    def getMainInform(self):
        downloader = DownloadDecorator(self.session)

        url = self.createApi.friends.get()
        downloader(url, self.countFriends, 'friends')

        url = self.createApi.groups.get()
        downloader(url, self.countGroups, 'groups')

        url = self.createApi.photos.getAll(no_service_albums=0,
                                           skip_hidden=1,
                                           count=200)
        downloader(url, 'None', 'allPhotos')

        url = self.createApi.wall.get(extended=1, count=self.curCountRecords)
        downloader(url, 'None', 'wall')

        url = self.createApi.account.getProfileInfo()
        downloader(url, 'None', 'profileInfo')

        # Download and dispersal
        download = downloader.download()
        for item in download:

            if item[2] == 'friends':
                countFriends = item[1]
                self.dataFriends = json.loads(item[0].text)
                self.countFriends.setText(
                    str(self.dataFriends['response']['count']))

            if item[2] == 'groups':
                j = json.loads(item[0].text)
                self.dataGroups = j['response']
                self.countGroups.setText(str(self.dataGroups['count']))

            if item[2] == 'allPhotos':
                j = json.loads(item[0].text)
                self.dataAllPhotos = j['response']
                self.countPhoto.setText(str(self.dataAllPhotos['count']))

            if item[2] == 'wall':
                j = json.loads(item[0].text)
                self.dataWall = j['response']

            if item[2] == 'profileInfo':
                j = json.loads(item[0].text)
                self.dataInfo = j['response']

                lines = [
                    self.lineName, self.lineLastName, self.lineBD,
                    self.lineHomeTown, self.lineStatus, self.lineCountry,
                    self.lineCity, self.lineCityId
                ]

                mas = [
                    'first_name', 'last_name', 'bdate', 'home_town', 'status',
                    'country', 'city', 'cityId'
                ]

                for i in range(len(lines)):
                    item = lines[i]

                    if mas[i] == 'country':
                        try:
                            item.setText(self.dataInfo['country']['title'])
                        except:
                            item.setText('None')

                    elif mas[i] == 'city':
                        try:
                            item.setText(self.dataInfo['city']['title'])
                        except KeyError:
                            item.setText('None')

                    elif mas[i] == 'cityId':
                        try:
                            item.setText(str(self.dataInfo['city']['id']))
                        except KeyError:
                            item.setText('None')

                    else:
                        try:
                            item.setText(self.dataInfo[mas[i]])
                        except KeyError:
                            item.setText('None')

                self.name = self.lineName.text()
                self.lastName = self.lineLastName.text()
                self.BD = self.lineBD
                self.homeTown = self.lineHomeTown
                self.cityId = self.lineCityId