예제 #1
0
    def _lookup(self):
        url = self.ui.url.text().strip()
        if not url:
            return

        print('\nLooking up "%s" ...' % url)
        self._t0 = time.time()
        self._chunks = 0
        self._canceled = False

        if self._manager is None:
            self._manager = QtNetwork.QNetworkAccessManager(self)

        request = QtNetwork.QNetworkRequest(QtCore.QUrl(url))
        request.setRawHeader(b'User-Agent', b'MyOwnBrowser 1.0')
        reply = self._manager.get(request)
        reply.finished.connect(self._on_finish)
        reply.downloadProgress.connect(self._on_progress)
        reply.error[QtNetwork.QNetworkReply.NetworkError].connect(
            self._on_error)
        reply.sslErrors.connect(self._on_error)
        reply.readyRead.connect(self._on_ready_read)

        self._error_connected = False
        self._try_error_connection(reply)
예제 #2
0
    def set_source(self, value):
        # Don't do anything if source is changed to the same value
        if not NetworkImage.NETWORK_MANAGER or value == self.__source:
            return

        if not value:
            return

        self.__source = value

        if self.__should_blank_on_new_source:
            self.__has_image = False
            self.has_image_changed.emit()

        # Cancel previous ongoing request if exists
        if self.__reply:
            self.__reply.abort()

        if self.__source in NetworkImage.RAM_IMAGE_CACHE:
            # Immediately set image to cached version if exists
            self.update_image(NetworkImage.RAM_IMAGE_CACHE[self.__source])
        else:
            # If cached image doesn't exist, tell network manager to request from source
            self.__reply = NetworkImage.NETWORK_MANAGER.get(
                QtNetwork.QNetworkRequest(self.__source))
            self.__reply.finished.connect(self.handle_reply)
예제 #3
0
def createRequest(url):
    url = QtCore.QUrl(url)
    request = QtNetwork.QNetworkRequest(url)
    request.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader,
                      'application/json')

    return request
예제 #4
0
    def __init__(self):
        QtWidgets.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.sports = []
        self.ui.add_btn.clicked.connect(self._newForm)

        self.ui.item1 = QtWidgets.QListWidgetItem("Events")
        self.ui.main_list.addItem(self.ui.item1)
        self.ui.item2 = QtWidgets.QListWidgetItem("Results")
        self.ui.main_list.addItem(self.ui.item2)
        self.ui.main_list.itemClicked.connect(self._mainClicked)

        self.manager = QtNetwork.QNetworkAccessManager()
        self.sport_req = QtNetwork.QNetworkRequest(QtCore.QUrl("API URL"))
        self.sport_reply = self.manager.get(self.sport_req)
        self.sport_reply.finished.connect(self._sportsReply)

        self.ui.sport_combo.activated.connect(self._mainReq)
        self.ui.subClass_list.itemClicked.connect(self._loadForm)
        self.sport_dic = {}
        self.loaded = []
        self.resizeTimer = QtCore.QTimer()
        self.resizeTimer.setSingleShot(True)
        self.resizeTimer.timeout.connect(self.tryResize)
예제 #5
0
def sendUpload(row):
    upload = UploadList.uploads[row]
    upload['uploading'] = True
    filename = upload['name'].split('/')[-1]

    multiPart = QtNetwork.QHttpMultiPart(
        QtNetwork.QHttpMultiPart.ContentType.RelatedType)
    filedata = QtNetwork.QHttpPart()
    filedata.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader,
                       "image/jpeg")
    filedata.setHeader(QtNetwork.QNetworkRequest.ContentDispositionHeader,
                       "form-data; name=media;")

    file = QtCore.QFile(upload['name'])
    file.open(QtCore.QIODevice.ReadOnly)
    file.setParent(multiPart)
    upload['stream'] = file
    filedata.setBodyDevice(file)
    multiPart.append(filedata)
    upload['multiPart'] = multiPart

    url = QtCore.QUrl('http://127.0.0.1:8000/medias')
    request = QtNetwork.QNetworkRequest()
    request.setUrl(url)
    request.setRawHeader('Authorization'.encode(),
                         ('Bearer ' + Login.token).encode())
    request.setRawHeader('FILENAME'.encode(), filename.encode())
    upload['manager'] = QtNetwork.QNetworkAccessManager()
    try:
        upload['reply'] = upload['manager'].post(request, upload['multiPart'])
        upload['manager'].setParent(upload['reply'])
        upload['reply'].uploadProgress.connect(updateProgress(upload, row))
    except Exception as e:
        print(e)
예제 #6
0
def requestList(manager):
    url = QtCore.QUrl('http://127.0.0.1:8000/medias')
    request = QtNetwork.QNetworkRequest()
    request.setUrl(url)
    request.setRawHeader('Authorization'.encode(),
                         ('Bearer ' + Login.token).encode())
    manager.get(request)
예제 #7
0
 def get_updates(self):
     url = settings.get(
         SettingType.CHECK_UPDATE_URL,
         'https://api.github.com/repos/juliendz/imagius/releases/latest')
     qurl = QtCore.QUrl(url)
     LOGGER.info("Checking for updates....")
     self._net_mgr.get(QtNetwork.QNetworkRequest(qurl))
예제 #8
0
 def run_command(self, command, **kwargs):
     request = QtNetwork.QNetworkRequest(
         QtCore.QUrl('http://localhost:7954/' + command))
     request.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader,
                       "application/x-www-form-urlencoded")
     reply = self.network.post(request, dict_to_post_data(kwargs))
     # reply.finished.connect(cb)
     reply.error.connect(self.on_command_error)
예제 #9
0
 def time_by_city(self, city: str) -> None:
     url = QUrl(WeatherDate.BASE_URL)
     query = QUrlQuery()
     query.addQueryItem("q", city)
     query.addQueryItem("appid", self.api_key)
     url.setQuery(query)
     request = QtNetwork.QNetworkRequest(url)
     reply: QtNetwork.QNetworkReply = self.manager.get(request)
     reply.finished.connect(self.tim)
예제 #10
0
    def leaguesReq(self, sport_id):

        dic = {"sports": [{"id": sport_id}]}
        vari_req = QtCore.QJsonDocument.fromVariant(dic)
        json_req = QtCore.QJsonDocument.toJson(vari_req)

        req = QtNetwork.QNetworkRequest(QtCore.QUrl("API URL"))
        req.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader,
                      "application/json")
        self.league_reply = self.manager.post(req, json_req)
        self.league_reply.finished.connect(self._leaguesReply)
예제 #11
0
    def update_by_city(self, city: str):

        url = QUrl(WeatherWrapper.BASE_URL)
        query = QUrlQuery()
        query.addQueryItem("q", city)
        query.addQueryItem("appid", self.api_key)
        url.setQuery(query)

        request = QtNetwork.QNetworkRequest(url)
        reply: QtNetwork.QNetworkReply = self.manager.get(request)
        reply.finished.connect(self._handle_reply)
예제 #12
0
    def _tick(self):
        print("TICK")
        if self.request is not None:
            return
        objgraph.show_growth()
        print(objgraph.typestats())

        self.request = QtNetwork.QNetworkRequest()
        self.request.setUrl(QtCore.QUrl(self.url))
        self.request.setRawHeader(b"User-Agent", b"Test")
        self.reply = self.manager.get(self.request)
        self.reply.finished.connect(self._finished)
예제 #13
0
 def __create_get_request(self, url: str) -> QtNetwork.QNetworkRequest:
     request = QtNetwork.QNetworkRequest(QtCore.QUrl(url))
     request.setAttribute(
         QtNetwork.QNetworkRequest.RedirectPolicyAttribute,
         QtNetwork.QNetworkRequest.UserVerifiedRedirectPolicy,
     )
     request.setAttribute(
         QtNetwork.QNetworkRequest.CacheSaveControlAttribute, False)
     request.setAttribute(
         QtNetwork.QNetworkRequest.CacheLoadControlAttribute,
         QtNetwork.QNetworkRequest.AlwaysNetwork,
     )
     return request
    def start_fetch(self, network_manager: QtNetwork.QNetworkAccessManager):
        """Asynchronously begin the network access. Intended as a set-and-forget black box for downloading files."""

        self.request = QtNetwork.QNetworkRequest(QtCore.QUrl(self.url))
        self.request.setAttribute(
            QtNetwork.QNetworkRequest.RedirectPolicyAttribute,
            QtNetwork.QNetworkRequest.UserVerifiedRedirectPolicy,
        )

        self.fetch_task = network_manager.get(self.request)
        self.fetch_task.finished.connect(self.resolve_fetch)
        self.fetch_task.redirected.connect(self.on_redirect)
        self.fetch_task.sslErrors.connect(self.on_ssl_error)
예제 #15
0
    def __init__(self):
        super(Requests, self).__init__()

        # use qt for http requests, type has to be set to application/json
        self.request = QtNetwork.QNetworkRequest()
        self.request.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader,
                               "application/json")
        self.manager = QtNetwork.QNetworkAccessManager()

        # grab dictionary template
        self.render = ReplayApiData.render
        self.playback = ReplayApiData.playback
        self.fov = ReplayApiData.fov
예제 #16
0
 def __create_get_request(self, url: str) -> QtNetwork.QNetworkRequest:
     """Construct a network request to a given URL"""
     request = QtNetwork.QNetworkRequest(QtCore.QUrl(url))
     request.setAttribute(
         QtNetwork.QNetworkRequest.RedirectPolicyAttribute,
         QtNetwork.QNetworkRequest.UserVerifiedRedirectPolicy,
     )
     request.setAttribute(
         QtNetwork.QNetworkRequest.CacheSaveControlAttribute, True)
     request.setAttribute(
         QtNetwork.QNetworkRequest.CacheLoadControlAttribute,
         QtNetwork.QNetworkRequest.PreferNetwork,
     )
     return request
예제 #17
0
 def __create_get_request(self, url: str) -> QtNetwork.QNetworkRequest:
     request = QtNetwork.QNetworkRequest(QtCore.QUrl(url))
     request.setAttribute(
         QtNetwork.QNetworkRequest.RedirectPolicyAttribute,
         QtNetwork.QNetworkRequest.UserVerifiedRedirectPolicy,
     )
     request.setAttribute(
         QtNetwork.QNetworkRequest.CacheSaveControlAttribute, True)
     request.setAttribute(
         QtNetwork.QNetworkRequest.CacheLoadControlAttribute,
         QtNetwork.QNetworkRequest.PreferCache,
     )
     request.setAttribute(
         QtNetwork.QNetworkRequest.BackgroundRequestAttribute, True)
     return request
예제 #18
0
    def get_request(self,
                    url: str,
                    callback: Callable[[QNetworkReply, dict], None],
                    referer: str = None,
                    meta_dict=None):
        req = QtNetwork.QNetworkRequest(QtCore.QUrl(url))
        req.setHeader(
            QtNetwork.QNetworkRequest.UserAgentHeader,
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'
        )

        req.setAttribute(QtNetwork.QNetworkRequest.FollowRedirectsAttribute,
                         True)
        if referer is not None:
            req.setRawHeader(bytes('Referer', 'utf-8'),
                             bytes(referer, 'utf-8'))
        reply = self._manager.get(req)
        reply.finished.connect(partial(callback, reply, meta_dict))
예제 #19
0
    def _mainReq(self):
        self.ui.subClass_list.clear()
        self.ui.add_btn.setEnabled(True)
        self.selected_sport = self.sport_dic.get(
            self.ui.sport_combo.currentText())
        selected = self.ui.main_list.currentItem()
        if selected.text() == "Events":
            dic = {"offset": 0, "limit": 100, "sport_id": self.selected_sport}
            vari_req = QtCore.QJsonDocument.fromVariant(dic)
            json_req = QtCore.QJsonDocument.toJson(vari_req)

            req = QtNetwork.QNetworkRequest(QtCore.QUrl("API URL"))
            req.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader,
                          "application/json")
            self.event_reply = self.manager.post(req, json_req)
            self.event_reply.finished.connect(self._eventsReply)

        if selected.text() == "Results":
            pass