Beispiel #1
0
	def numberOfUsersToActuallyUnfollow(self):
		response = Request().get("/report/daily-report/fetch")
		usersUnfollowedToday = response.json()["unfollowed"]
		usersToUnfollowTillLimit = config.unfollow_per_day

		usersToUnfollowPerBatch = (config.unfollow_per_day / config.unfollow_batches)

		return int(min(usersToUnfollowTillLimit, usersToUnfollowPerBatch))
Beispiel #2
0
	def usersToUnfollow(self):
		response = Request().post("/users-to-unfollow", {"unfollowUsersAfter": config.follow_time})
		allUsersToUnfollow = response.json()
		numberOfUsersToActuallyUnfollow = self.numberOfUsersToActuallyUnfollow()

		allUsersToUnfollowLength= len(allUsersToUnfollow)
		numberOfUsersToActuallyUnfollow = numberOfUsersToActuallyUnfollow if numberOfUsersToActuallyUnfollow < allUsersToUnfollowLength else allUsersToUnfollowLength
		return allUsersToUnfollow[:numberOfUsersToActuallyUnfollow]
Beispiel #3
0
    def postIsAlreadyInDatabase(self):
        parameters = {"insta_id": self.instaId}
        request = Request().post("/post/exists", parameters)

        if request.status_code == 200:
            return request.json()  # true or false
        else:
            raise ScrapeExceptions.DatabaseError()
Beispiel #4
0
    def uploadPost(self, imagePath, caption):
        self.browser.get("https://instagram.com")

        addImageButton = self.browser.find_element_by_css_selector(
            "div._k0d2z._ttgfw._mdf8w")
        addImageButton.click()

        bottomBar = self.browser.find_element_by_css_selector(
            "nav._68u16._evlcw")
        imageInput = bottomBar.find_element_by_css_selector("input._l8al6")

        imageInput.send_keys(imagePath)

        sleep(5)

        # fullsizeButton = self.browser.find_element_by_css_selector("button._j7nl9")
        # fullsizeButton.click()
        nextButton = self.browser.find_element_by_css_selector("button._9glb8")
        nextButton.click()

        sleep(5)

        captionInput = self.browser.find_element_by_css_selector(
            "textarea._qlp0q")
        shareButton = self.browser.find_element_by_css_selector(
            "button._9glb8")

        sleep(2)
        ActionChains(self.browser).move_to_element(captionInput)\
         .click()\
         .send_keys(caption)\
         .click(shareButton)\
         .perform()

        Request().get("/post/posted/" + self.outstandingPost["insta_id"])
Beispiel #5
0
	def dailyReport(self):
		self.browser.get("https://www.instagram.com/" + config.instagram_username + "/")
		followerCount = self.browser.find_element_by_css_selector("a[href*='followers'] span").text
		followingCount = self.browser.find_element_by_css_selector("a[href*='following'] span").text

		Request().post("/report/follower-count", {"followerCount": followerCount, "followingCount": followingCount})

		Email(DailyReport(followerCount, followingCount)).send()
Beispiel #6
0
	def cleanOutScrapedImages(self):
		local = Local()
		try:
			# fetch images that have been disapproved or that have been posted
		    filepaths = Request().get("/post/can-be-deleted").json()
		    for filepath in filepaths:
		     	# check if the images exist in scraped images and delete them
		    	local.deleteIfExists(filepath)

		except JSONDecodeError:
		    print("no posts to delete")
Beispiel #7
0
    def usersToUnfollow(self, users):
        usersUnfollowed = []
        usersAlreadyUnfollowed = []

        for user in users:
            username = user["username"]
            try:
                self.unfollow(username)
                usersUnfollowed.append(username)
            except FollowExceptions.UserAlreadyUnfollowed:
                # create two separate lists for unfollowed and already unfollowed because we don't want
                # the already unfollowed to be registered as newly unfollowed on the daily report
                usersAlreadyUnfollowed.append(username)

        unfollowingParameters = {"unfollowed": usersUnfollowed}
        Request().post("/followed/unfollow", json=unfollowingParameters)

        reportParameters = {"unfollowed": len(usersUnfollowed)}
        Request().post("/report/daily-report/increase", reportParameters)

        alreadyUnfollowedParameters = {"unfollowed": usersAlreadyUnfollowed}
        Request().post("/followed/unfollow", json=alreadyUnfollowedParameters)
Beispiel #8
0
    def generateMessage(self):
        dailyStats = Request().get("/report/daily-report/fetch").json()

        likedToday = "{} posts were liked today.".format(dailyStats["liked"])
        commentedToday = "{} posts were commented on today.".format(
            dailyStats["commented"])
        followedToday = "{} users have been followed today.".format(
            dailyStats["followed"])
        unfollowedToday = "{} users have been unfollowed today.".format(
            dailyStats["unfollowed"])
        postedToday = "{} pictures were posted today".format(
            dailyStats["posted"])
        totalFollowers = "Total follower count is: {}".format(
            self.totalFollowerCount)
        totalFollowing = "Total following count is: {}".format(
            self.totalFollowingCount)

        messageText = "{}\n{}\n{}\n{}\n{}\n{}\n{}\n"
        finalMessage = messageText.format(likedToday, commentedToday,
                                          followedToday, unfollowedToday,
                                          postedToday, totalFollowers,
                                          totalFollowing)
        self.message = finalMessage
Beispiel #9
0
    def generateMessage(self):
        dailyStats = Request().get("/post/daily-stats").json()

        url = config.base_website + "/evaluate/" + config.bot_account_id
        postsScrapedTodayMessage = "{} posts were scraped today.".format(
            dailyStats["scrapedToday"])
        postBacklogMessage = "{} posts are in the backlog.".format(
            dailyStats["inBacklog"])
        postBacklogMessageAddon = "!!!!" if dailyStats["inBacklog"] < 10 else ""
        toBeApproved = "{} posts have yet to be approved.".format(
            dailyStats["toBeApproved"])

        messageText = """
		{}
		{} {}
		{}
		To evaluate posts, visit: {}
		"""
        finalMessage = messageText.format(postsScrapedTodayMessage,
                                          postBacklogMessage,
                                          postBacklogMessageAddon,
                                          toBeApproved, url)
        self.message = finalMessage
Beispiel #10
0
    def savePostToDatabase(self):
        self.scrapeAttributes()

        parameters = {
            "originally_posted_at": self.originallyPostedAt,
            "scraped_at":
            datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            "posted_at": None,
            "insta_id": self.instaId,
            "file_path": self.instaId,
            "instagram_post_url": self.postUrl,
            "instagram_image_url": self.imageUrl,
            "owner_username": self.ownerUserName,
            "original_caption": self.originalCaption,
            "approved": 0,
            "disapproved": 0,
        }
        request = Request().post("/post", parameters)

        if request.status_code == 200:
            return True
        else:
            raise ScrapeExceptions.DatabaseError()
Beispiel #11
0
 def outstandingPost(self):
     request = Request().get("/post/fetch")
     sleep(10)
     return request.json()
Beispiel #12
0
 def uploadLimitNotReached(self):
     postsPerDay = config.posts_per_day
     alreadyPostedToday = Request().get(
         "/report/daily-report/fetch").json()["posted"]
     return alreadyPostedToday < postsPerDay
Beispiel #13
0
 def scrapingIncomplete(self):
     postBacklogAmount = Request().get("/post/backlog/amount").json()
     return postBacklogAmount < config.post_backlog
Beispiel #14
0
    def recordNewFollowings(self, newFollowings):
        followingParameters = {"followed": newFollowings}
        request = Request().post("/followed/follow", json=followingParameters)

        reportParameters = {"followed": len(newFollowings)}
        Request().post("/report/daily-report/increase", reportParameters)