Пример #1
0
def main():
    i = 0
    apikeys = 3
    delay = 10
    #Initialize Google Geocoder API
    geocodes = [
        "AIzaSyALEw3mSl_8MBk8jBtx5FX_iU4Q6QTYlxk",
        "AIzaSyCmw7Sdg3nVMoV3QmloLCOTtIs2jSlSNYk",
        "AIzaSyBbsYKdYK8HUyJ-77ChVswOyZ6envEtIc8"
    ]
    geocoder = pygeocoder.Geocoder(geocodes[0])
    counter = 0
    with open("friends.csv") as user_list:
        users = csv.reader(user_list, delimiter='|')
        for user in users:
            name = user[0]
            handler = user[1]
            img_link = user[2]
            location = user[3]
            connections = user[4]
            print user
            result = coordlocation(geocoder, name, handler, img_link,
                                   connections, location)
            if result == 0:
                i += 1
                if i == apikeys:
                    i = 0
                    time.sleep(delay)
                geocoder = pygeocoder.Geocoder(geocodes[i])
                result = coordlocation(geocoder, name, handler, img_link,
                                       connections, location)
Пример #2
0
	def __init__(self, location_str="Claremont Colleges", user=None):
		# Initialize Google Geocoder API
		geocoder = pygeocoder.Geocoder("AIzaSyAGeW6l17ATMZiNTRExwvfa2iuPA1DvJqM")
		self.coordlocation = self.setLocation(geocoder, location_str)
		if (self.coordlocation==None):
			raise "BAD LOCATION"
		self.remoteyakker = pk.Yakker(user, self.coordlocation, True)
		currentlist = []
Пример #3
0
def google_v3(premise):
    '''Geocode a premise using the pygeocoder library.'''
    # Workaround pylint unsupporting static methods
    geocoder = pygeocoder.Geocoder()

    address = "{0}, {1}, Hong Kong".format(premise['name'], premise['address'])
    try:
        results = geocoder.geocode(address)
    except pygeocoder.GeocoderError:
        address = "{0}, Hong Kong".format(premise['name'])
        try:
            results = geocoder.geocode(address)
        except pygeocoder.GeocoderError:
            raise
    return results.coordinates
Пример #4
0
def main():
    # Title text
    print("\nYik Yak Command Line Edition : Created by djtech42\n\n")

    # Initialize Google Geocoder API
    geocoder = pygeocoder.Geocoder("AIzaSyAGeW6l17ATMZiNTRExwvfa2iuPA1DvJqM")

    # We only care about $SCHOOL_NAME, no need for the entire CSV file schools
    schools_list = ["$SCHOOL_NAME"]
    # the CSV file you should have downloaded
    #with open('schools_list.csv','r') as school_file:
    #	school_reader = csv.reader(school_file)
    #	for row in school_reader:
    #		schools_list.append(row[0])

    try:
        # If location already set in past, read file
        f = open("locationsetting", "r")
        fileinput = f.read()
        f.close()

        # Extract location coordinates and name from file
        coords = fileinput.split('\n')

        currentlatitude = coords[0]
        currentlongitude = coords[1]
        print("Location is set to: ", coords[2])

        # Set up coordinate object
        coordlocation = pk.Location(currentlatitude, currentlongitude)

    except FileNotFoundError:
        # If first time using app, ask for preferred location
        coordlocation = newLocation(geocoder)

        # If location retrieval fails, ask user for coordinates
        if coordlocation == 0:
            print("Please enter coordinates manually: ")

            currentlatitude = input("Latitude: ")
            currentlongitude = input("Longitude: ")
            coordlocation = pk.Location(currentlatitude, currentlongitude)

    print()

    try:
        # If user already has ID, read file
        f = open("userID", "r")
        userID = f.read()
        f.close()

        # start API with saved user ID
        remoteyakker = pk.Yakker(userID, coordlocation, False)

    except FileNotFoundError:
        # start API and create new user ID
        remoteyakker = pk.Yakker(None, coordlocation, True)

        try:
            # Create file if it does not exist and write user ID
            f = open("userID", 'w+')
            f.write(remoteyakker.id)
            f.close()

        except:
            pass

    # Print User Info Text
    print("User ID: ", remoteyakker.id, "\n")
    print("Connecting to Yik Yak server...\n")
    connection = True
    try:
        print("Yakarma Level:", remoteyakker.get_yakarma(), "\n")
    except:
        print("Error: Not connected to the Internet\n")
        connection = False
    if connection:
        print(
            "Type one of the one-letter commands below or use the command in conjunction with a parameter."
        )

        currentlist = []

        # When actions are completed, user can execute another action or quit the app
        while True:
            # Insert line gap
            print()

            # Show all action choices
            choice = input(
                "*Read Latest Yaks\t\t(R)\n*Write Yaks to CSV File\t\t(W)\n\n*Post Yak\t\t\t(P) or (P <message>)\n*Post Comment\t\t\t(C) or (C <yak#>)\n\n*Upvote Yak\t\t\t(U) or (U <yak#>)\n*Downvote Yak\t\t\t(D) or (D <yak#>)\n*Report Yak\t\t\t(E) or (E <yak#>)\n*Show Recent Yak Upvotes\t(A)\n\n*Upvote Comment\t\t\t(V) or (V <yak# comment#>)\n*Downvote Comment\t\t(H) or (H <yak# comment#>)\n*Report Comment\t\t\t(M) or (M <yak# comment#>)\n\n*Yakarma Level\t\t\t(Y)\n\n*Choose New User ID\t\t(I) or (I <userID>)\n*Choose New Location\t\t(L) or (L <location>)\n\n*Contact Yik Yak\t\t(F)\n\n*Quit App\t\t\t(Q)\n\n-> "
            )

            # Where the magic happens
            if choice.upper() == 'W':
                with open('all_yaks.csv', 'wt') as f:
                    for school in schools_list:
                        # update our location to the current school
                        coordlocation = changeLocation(geocoder, school)
                        remoteyakker.update_location(coordlocation)
                        for i in remoteyakker.get_yaks():
                            writer = csv.writer(f)
                            # write out whatever values you desire
                            writer.writerow([str(i.message), school, i.likes])

            # Read Yaks
            if choice.upper() == 'R':
                currentlist = remoteyakker.get_yaks()
                read(currentlist)

            # Read Local Top Yaks
            elif choice.upper() == 'T':
                currentlist = remoteyakker.get_area_tops()
                read(currentlist)

            # Read Best of All Time
            elif choice.upper() == 'B':
                currentlist = remoteyakker.get_greatest()
                read(currentlist)

            # Show User Yaks
            elif choice.upper() == 'S':
                currentlist = remoteyakker.get_my_recent_yaks()
                read(currentlist)

            # Show User Comments
            elif choice.upper() == 'O':
                currentlist = remoteyakker.get_recent_replied()
                read(currentlist)

            elif choice.upper() == 'G':
                currentlist = remoteyakker.get_my_tops()
                read(currentlist)

            # Show Recent Yak Upvotes
            elif choice.upper() == 'A':
                currentlist = remoteyakker.get_yaks()
                upvotedlist = []
                for yak in currentlist:
                    if yak.liked:
                        upvotedlist.append(yak)
                if len(upvotedlist) == 0:
                    print("No recent upvotes")
                read(upvotedlist)

            # Post Yak
            elif choice[0].upper() == 'P':
                # set message from parameter or input
                if len(choice) > 2:
                    message = choice[2:]
                else:
                    message = input("Enter message to yak: \n")

                # handle and location options
                handle = input("Add handle: (Blank to omit): \n")
                showlocation = input("Show location? (Y/N) ")

                if showlocation.upper() == 'Y':
                    allowlocation = True
                else:
                    allowlocation = False

                if handle == '':
                    posted = remoteyakker.post_yak(message,
                                                   showloc=allowlocation)
                else:
                    posted = remoteyakker.post_yak(message,
                                                   showloc=allowlocation,
                                                   handle=handle)

                if posted:
                    if len(remoteyakker.get_my_recent_yaks()
                           ) > 0 and remoteyakker.get_my_recent_yaks(
                           )[0].message == message:
                        print("\nYak successful :)")
                    else:
                        print("\nYak failed :(\t", end='')
                else:
                    print("\nYak failed :(\t", end='')
                    print(posted.status_code, end='')
                    print(" ", end='')
                    print(requests.status_codes._codes[posted.status_code][0])

            # Post Comment
            elif choice[0].upper() == 'C':
                # If yaks not loaded, tell user to load one of the options
                if len(currentlist) > 0:
                    # set message from parameter or input
                    if len(choice) > 2:
                        yakNum = int(choice[2:])
                    else:
                        yakNum = int(
                            input(
                                "Enter yak number (displayed above each one): "
                            ))

                    comment = input("Enter comment:\n")

                    posted = remoteyakker.post_comment(
                        currentlist[yakNum - 1].message_id, comment)

                    if posted:
                        if len(remoteyakker.get_recent_replied()
                               ) > 0 and remoteyakker.get_recent_replied(
                               )[0].get_comments()[:-1] == comment:
                            print("\nComment successful :)")
                        else:
                            print("\nComment failed :(\t", end='')
                    else:
                        print("\nComment failed :(\t", end='')
                        print(posted.status_code, end='')
                        print(" ", end='')
                        print(requests.status_codes._codes[posted.status_code]
                              [0])

                else:
                    print(
                        "You must load a list of yaks first by reading latest, top local, best, or user yaks."
                    )

            # Upvote Yak
            elif choice[0].upper() == 'U':
                # If yaks not loaded, tell user to load one of the options
                if len(currentlist) > 0:
                    if len(choice) > 2:
                        # Extract yak number
                        voteYakNum = int(choice[2:])
                    else:
                        voteYakNum = int(
                            input(
                                "Enter yak number to upvote (displayed above each one): "
                            ))

                    upvoted = remoteyakker.upvote_yak(
                        currentlist[voteYakNum - 1].message_id)

                    if upvoted:
                        print("\nUpvote successful :)")
                    else:
                        print("\nUpvote failed :(\t", end='')
                        print(posted.status_code, end='')
                        print(" ", end='')
                        print(requests.status_codes._codes[posted.status_code]
                              [0])

                else:
                    print(
                        "You must load a list of yaks first by reading latest, top local, best, or user yaks."
                    )

            # Downvote Yak
            elif choice[0].upper() == 'D':
                # If yaks not loaded, tell user to load one of the options
                if len(currentlist) > 0:
                    if len(choice) > 2:
                        # Extract yak number
                        voteYakNum = int(choice[2:])
                    else:
                        voteYakNum = int(
                            input(
                                "Enter yak number to downvote (displayed above each one): "
                            ))

                    downvoted = remoteyakker.downvote_yak(
                        currentlist[voteYakNum - 1].message_id)

                    if downvoted:
                        print("\nDownvote successful :)")
                    else:
                        print("\nDownvote failed :(\t", end='')
                        print(posted.status_code, end='')
                        print(" ", end='')
                        print(requests.status_codes._codes[posted.status_code]
                              [0])

                else:
                    print(
                        "You must load a list of yaks first by reading latest, top local, best, or user yaks."
                    )

            # Report Yak
            elif choice[0].upper() == 'E':
                # If yaks not loaded, tell user to load one of the options
                if len(currentlist) > 0:
                    if len(choice) > 2:
                        # Extract yak number
                        reportYakNum = int(choice[2:])
                    else:
                        reportYakNum = int(
                            input(
                                "Enter yak number to report (displayed above each one): "
                            ))

                    reported = remoteyakker.report_yak(
                        currentlist[reportYakNum - 1].message_id)

                    if reported:
                        print("\nReport successful :)")
                    else:
                        print("\nReport failed :(\t", end='')
                        print(posted.status_code, end='')
                        print(" ", end='')
                        print(requests.status_codes._codes[posted.status_code]
                              [0])

                else:
                    print(
                        "You must load a list of yaks first by reading latest, top local, best, or user yaks."
                    )

            # Upvote Comment
            elif choice[0].upper() == 'V':
                # If yaks not loaded, tell user to load one of the options
                if len(currentlist) > 0:
                    parameters = choice.split()

                    if len(parameters) == 3:
                        yakNum = int(parameters[1])
                        voteCommentNum = int(parameters[2])
                    elif len(parameters) == 2:
                        yakNum = int(parameters[1])
                        voteCommentNum = int(
                            input(
                                "Enter comment number to upvote (displayed above each one): "
                            ))
                    else:
                        yakNum = int(
                            input(
                                "Enter yak number (displayed above each one): "
                            ))
                        voteCommentNum = int(
                            input(
                                "Enter comment number to upvote (displayed above each one): "
                            ))

                    upvoted = remoteyakker.upvote_comment(
                        currentlist[yakNum - 1].get_comments()[voteCommentNum -
                                                               1].comment_id)

                    if upvoted:
                        print("\nUpvote successful :)")
                    else:
                        print("\nUpvote failed :(\t", end='')
                        print(posted.status_code, end='')
                        print(" ", end='')
                        print(requests.status_codes._codes[posted.status_code]
                              [0])

                else:
                    print(
                        "You must load a list of yaks first by reading latest, top local, best, or user yaks."
                    )

            # Downvote Comment
            elif choice[0].upper() == 'H':
                # If yaks not loaded, tell user to load one of the options
                if len(currentlist) > 0:
                    parameters = choice.split()

                    if len(parameters) == 3:
                        yakNum = int(parameters[1])
                        voteCommentNum = int(parameters[2])
                    elif len(parameters) == 2:
                        yakNum = int(parameters[1])
                        voteCommentNum = int(
                            input(
                                "Enter comment number to downvote (displayed above each one): "
                            ))
                    else:
                        yakNum = int(
                            input(
                                "Enter yak number (displayed above each one): "
                            ))
                        voteCommentNum = int(
                            input(
                                "Enter comment number to downvote (displayed above each one): "
                            ))

                    downvoted = remoteyakker.downvote_comment(
                        currentlist[yakNum - 1].get_comments()[voteCommentNum -
                                                               1].comment_id)

                    if downvoted:
                        print("\nDownvote successful :)")
                    else:
                        print("\nDownvote failed :(\t", end='')
                        print(posted.status_code, end='')
                        print(" ", end='')
                        print(requests.status_codes._codes[posted.status_code]
                              [0])

                else:
                    print(
                        "You must load a list of yaks first by reading latest, top local, best, or user yaks."
                    )

            # Report Comment
            elif choice[0].upper() == 'M':
                # If yaks not loaded, tell user to load one of the options
                if len(currentlist) > 0:
                    parameters = choice.split()

                    if len(parameters) == 3:
                        yakNum = int(parameters[1])
                        reportCommentNum = int(parameters[2])
                    elif len(parameters) == 2:
                        yakNum = int(parameters[1])
                        reportCommentNum = int(
                            input(
                                "Enter comment number to report (displayed above each one): "
                            ))
                    else:
                        yakNum = int(
                            input(
                                "Enter yak number (displayed above each one): "
                            ))
                        reportCommentNum = int(
                            input(
                                "Enter comment number to report (displayed above each one): "
                            ))

                    reported = remoteyakker.report_comment(
                        currentlist[yakNum -
                                    1].get_comments()[reportCommentNum -
                                                      1].comment_id)

                    if reported:
                        print("\nReport successful :)")
                    else:
                        print("\nReport failed :(\t", end='')
                        print(posted.status_code, end='')
                        print(" ", end='')
                        print(requests.status_codes._codes[posted.status_code]
                              [0])

                else:
                    print(
                        "You must load a list of yaks first by reading latest, top local, best, or user yaks."
                    )

            # Yakarma Level
            elif choice.upper() == 'Y':
                print("\nYakarma Level:", remoteyakker.get_yakarma())

            # Change User ID
            elif choice[0].upper() == 'I':
                if len(choice) > 2:
                    remoteyakker = setUserID(remoteyakker.location, choice[2:])
                else:
                    remoteyakker = setUserID(remoteyakker.location)

                # Print User Info Text
                print("\nUser ID: ", remoteyakker.id, "\n")
                print("Connecting to Yik Yak server...\n")
                print("Yakarma Level:", remoteyakker.get_yakarma(), "\n")

            # Change Location
            elif choice[0].upper() == 'L':
                # set location from parameter or input
                if len(choice) > 2:
                    coordlocation = changeLocation(geocoder, choice[2:])
                else:
                    coordlocation = changeLocation(geocoder)

                remoteyakker.update_location(coordlocation)

                yaklist = remoteyakker.get_yaks()
                currentlist = yaklist

            # Contact Yik Yak
            elif choice.upper() == 'F':
                message = input("Enter message to send to Yik Yak: ")
                contacted = remoteyakker.contact(message)
                if contacted:
                    print("\nYik Yak contacted successfully :)")
                else:
                    print("\nFailed to contact Yik Yak :(\t", end='')
                    print(posted.status_code, end='')
                    print(" ", end='')
                    print(requests.status_codes._codes[posted.status_code][0])

            # Quit App
            elif choice.upper() == 'Q':
                break
Пример #5
0
def main():

    # Initialize Google Geocoder API
    geocoder = pygeocoder.Geocoder("AIzaSyB3X2bU_oHFuiYUpcHog_jQhaR-zN-3cmE")
    try:
        # If user already has ID, read file
        f = open("userID", "r")
        userID = f.read()
        f.close()

        # start API with saved user ID
        remoteyakker = pk.Yakker(userID, None, False)

    except FileNotFoundError:
        # start API and create new user ID
        remoteyakker = pk.Yakker(None, None, True)

        try:
            # Create file if it does not exist and write user ID
            f = open("userID", 'w+')
            f.write(remoteyakker.id)
            f.close()

        except:
            pass
    currentlist = []
    # Locations to query
    # Columbia University
    # Claremont Colleges
    # Georgia Southern University
    # Texas A&M
    # Clemson University
    # Wake Forest University
    # Stanford University
    # Colgate University
    # University of Utah
    # colleges = ["Columbia University","Claremont Colleges","Georgia Southern University","Texas A&M","Clemson University","Wake Forest University","Stanford University","Colgate University","University of Utah"]
    collegeFiles = {
        "Columbia University": "columbiaFile.txt",
        "Claremont Colleges": "claremontFile.txt",
        "Georgia Southern University": "georgiaFile.txt",
        "Texas A&M": "texasFile.txt",
        "Clemson University": "clemsonFile.txt",
        "Wake Forest University": "wakeFile.txt",
        "Stanford University": "stanfordFile.txt",
        "Colgate University": "colgateFile.txt",
        "University of Utah": "utahFile.txt"
    }
    timeRadius = 5
    timesToCollect = {
        "1hour": (60 - timeRadius, 60 + timeRadius),
        "2hour": (120 - timeRadius, 120 + timeRadius),
        "3hour": (180 - timeRadius, 180 + timeRadius),
        "4hour": (240 - timeRadius, 240 + timeRadius)
    }
    #get the locations for all of the colleges we care about
    collegeLocations = {}
    for college in collegeFiles.keys():
        try:
            collegeLocations[college] = newLocation(geocoder, college)
        except:
            print("Google Geolocation API isn't working for " + college +
                  " for some reason.")

    start_moment = datetime.now() - timedelta(minutes=timeRadius * 2)
    while True:
        end_moment = datetime.now()
        time_to_sleep = start_moment + timedelta(minutes=timeRadius *
                                                 2) - end_moment
        if (time_to_sleep.total_seconds() > 0):
            sleep(time_to_sleep.total_seconds())
        start_moment = datetime.now()

        for (schoolName, schoolFile) in collegeFiles.items():
            coordlocation = collegeLocations[
                schoolName]  #keep track of the locations & don't use the API
            remoteyakker.update_location(coordlocation)
            currentlist = remoteyakker.get_yaks()

            for (folderName, times) in timesToCollect.items():

                outFile = open("data/" + folderName + "/" + schoolFile, "a")
                # print(schoolName,schoolFile)
                read(currentlist, outFile, times)
                outFile.close()
Пример #6
0
def main():
    # Title text
    print("\nYik Yak Command Line Edition : Created by djtech42\n\n")

    # Initialize Google Geocoder API
    geocoder = pygeocoder.Geocoder("AIzaSyAGeW6l17ATMZiNTRExwvfa2iuPA1DvJqM")

    try:
        # If location already set in past, read file
        f = open("locationsetting", "r")
        fileinput = f.read()
        f.close()

        # Extract location coordinates and name from file
        coords = fileinput.split('\n')

        currentlatitude = coords[0]
        currentlongitude = coords[1]
        print("Location is set to: ", coords[2])

        # Set up coordinate object
        coordlocation = pk.Location(currentlatitude, currentlongitude)

    except FileNotFoundError:
        # If first time using app, ask for preferred location
        coordlocation = newLocation(geocoder)

        # If location retrieval fails, ask user for coordinates
        if coordlocation == 0:
            print("Please enter coordinates manually: ")

            currentlatitude = input("Latitude: ")
            currentlongitude = input("Longitude: ")
            coordlocation = pk.Location(currentlatitude, currentlongitude)

    print()

    try:
        # If user already has ID, read file
        f = open("userID", "r")
        userID = f.read()
        f.close()

        # start API with saved user ID
        remoteyakker = pk.Yakker(userID, coordlocation, False)

    except FileNotFoundError:
        # start API and create new user ID
        remoteyakker = pk.Yakker(None, coordlocation, True)

        try:
            # Create file if it does not exist and write user ID
            f = open("userID", 'w+')
            f.write(remoteyakker.id)
            f.close()

        except:
            pass

    # Print User Info Text
    print("User ID: ", remoteyakker.id, "\n")
    print("Connecting to Yik Yak server...\n")
    connection = True
    try:
        print("Yakarma Level:", remoteyakker.get_yakarma(), "\n")
    except:
        print("Error: Not connected to the Internet\n")
        connection = False
    if connection:
        print(
            "Type one of the one-letter commands below or use the command in conjunction with a parameter."
        )

        currentlist = []

        # When actions are completed, user can execute another action or quit the app
        while True:
            # Insert line gap
            print()

            # Show all action choices
            choice = input(
                "*Read Latest Yaks\t\t(R)\n*Read Top Local Yaks\t\t(T)\n\n*Read Best Yaks of All Time\t(B)\n\n*Show User Yaks\t\t\t(S)\n*Show User Comments\t\t(O)\n\n*Show Top User Yaks\t\t(G)\n\n*Post Yak\t\t\t(P) or (P <message>)\n*Post Comment\t\t\t(C) or (C <yak#>)\n\n*Upvote Yak\t\t\t(U) or (U <yak#>)\n*Downvote Yak\t\t\t(D) or (D <yak#>)\n*Report Yak\t\t\t(E) or (E <yak#>)\n*Show Recent Yak Upvotes\t(A)\n\n*Upvote Comment\t\t\t(V) or (V <yak# comment#>)\n*Downvote Comment\t\t(H) or (H <yak# comment#>)\n*Report Comment\t\t\t(M) or (M <yak# comment#>)\n\n*Yakarma Level\t\t\t(Y)\n\n*Choose New User ID\t\t(I) or (I <userID>)\n*Choose New Location\t\t(L) or (L <location>)\n\n*Contact Yik Yak\t\t(F)\n\n*Quit App\t\t\t(Q)\n\n-> "
            )

            # Read Yaks
            if choice.upper() == 'R':
                currentlist = remoteyakker.get_yaks()
                read(currentlist)

            # Read Local Top Yaks
            elif choice.upper() == 'T':
                currentlist = remoteyakker.get_area_tops()
                read(currentlist)

            # Read Best of All Time
            elif choice.upper() == 'B':
                currentlist = remoteyakker.get_greatest()
                read(currentlist)

            # Show User Yaks
            elif choice.upper() == 'S':
                currentlist = remoteyakker.get_my_recent_yaks()
                read(currentlist)

            # Show User Comments
            elif choice.upper() == 'O':
                currentlist = remoteyakker.get_recent_replied()
                read(currentlist)

            # Change User ID
            elif choice[0].upper() == 'I':
                if len(choice) > 2:
                    remoteyakker = setUserID(remoteyakker.location, choice[2:])
                else:
                    remoteyakker = setUserID(remoteyakker.location)

                # Print User Info Text
                print("\nUser ID: ", remoteyakker.id, "\n")
                print("Connecting to Yik Yak server...\n")
                print("Yakarma Level:", remoteyakker.get_yakarma(), "\n")

            # Change Location
            elif choice[0].upper() == 'L':
                # set location from parameter or input
                if len(choice) > 2:
                    coordlocation = changeLocation(geocoder, choice[2:])
                else:
                    coordlocation = changeLocation(geocoder)

                remoteyakker.update_location(coordlocation)

                yaklist = remoteyakker.get_yaks()
                currentlist = yaklist

            # Contact Yik Yak
            elif choice.upper() == 'F':
                message = input("Enter message to send to Yik Yak: ")
                contacted = remoteyakker.contact(message)
                if contacted:
                    print("\nYik Yak contacted successfully :)")
                else:
                    print("\nFailed to contact Yik Yak :(\t", end='')
                    print(posted.status_code, end='')
                    print(" ", end='')
                    print(requests.status_codes._codes[posted.status_code][0])

            # Quit App
            elif choice.upper() == 'Q':
                break
Пример #7
0
 def __init__(self):
     self.session = Session()
     self.stripper = re.compile(r'[\W+_]', re.UNICODE)
     self.geocoder = pygeocoder.Geocoder()
Пример #8
0
def main():
    # Title text
    print("\nYik Yak Command Line Edition : Created by djtech42\n\n")

    # Initialize Google Geocoder API
    geocoder = pygeocoder.Geocoder("AIzaSyAGeW6l17ATMZiNTRExwvfa2iuPA1DvJqM")

    try:
        # If location already set in past, read file
        f = open("locationsetting", "r")
        fileinput = f.read()
        f.close()

        # Extract location coordinates and name from file
        coords = fileinput.split('\n')

        currentlatitude = coords[0]
        currentlongitude = coords[1]
        print("Location is set to: ", coords[2])

        # Set up coordinate object
        coordlocation = pk.Location(currentlatitude, currentlongitude)

    except FileNotFoundError:
        # If first time using app, ask for preferred location
        coordlocation = newLocation(geocoder)

        # If location retrieval fails, ask user for coordinates
        if coordlocation == 0:
            print("Please enter coordinates manually: ")

            currentlatitude = input("Latitude: ")
            currentlongitude = input("Longitude: ")
            coordlocation = pk.Location(currentlatitude, currentlongitude)

    print()

    try:
        # If user already has ID, read file
        f = open("userID", "r")
        userID = f.read()
        f.close()

        # start API with saved user ID
        remoteyakker = pk.Yakker(userID, coordlocation, False)

    except FileNotFoundError:
        # start API and create new user ID
        remoteyakker = pk.Yakker(None, coordlocation, True)

        try:
            # Create file if it does not exist and write user ID
            f = open("userID", 'w+')
            f.write(remoteyakker.id)
            f.close()

        except:
            pass

    # Print User Info Text
    print("User ID: ", remoteyakker.id, "\n")
    print("Connecting to Yik Yak server...\n")

    def job():
        connection = True
        try:
            print("Yakarma Level:", remoteyakker.get_yakarma(), "\n")
        except:
            print("Error: Not connected to the Internet\n")
            connection = False
        if connection:
            currentlist = remoteyakker.get_yaks()
            time.sleep(1)
            for yak in currentlist:
                comments = yak.get_comments()
                yak.comments = comments
            with open(
                    "data/" +
                    datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") +
                    ".p", "wb") as infile:
                pickle.dump(currentlist, infile)
            print("Done")

    job()

    schedule.every(10).minutes.do(job)

    while (True):
        schedule.run_pending()
        time.sleep(1)
Пример #9
0
def main():
    print(
        "__________________________________________ \n \n \n Welcome to YikYak upvote Hack"
    )
    geocoder = pygeocoder.Geocoder("AIzaSyAGeW6l17ATMZiNTRExwvfa2iuPA1DvJqM")
    currentlist = []

    #Code pulled from YikYak.py terminal GUI. Because there is a problem with setting long and lat manually. Trying using google locations
    # If first time using app, ask for preferred location

    coordlocation = newLocation(geocoder)
    # If location retrieval fails, ask user for coordinates
    if coordlocation == 0:
        print("Please enter coordinates manually: ")
        currentlatitude = input("Latitude: ")
        currentlongitude = input("Longitude: ")
        coordlocation = pk.Location(currentlatitude, currentlongitude)

    #Optional Set Location input

    #print("Enter Location data for user upvotes");
    #location set based on long and lat input
    #currentlatitude = input("Latitude: ")
    #currentlongitude = input("Longitude: ")

    #temp hard coded in for easy testing
    #coordlocation = pk.Location("29.0355990", "-81.3034150")
    #longitude and latitude is: Lat 29.0355990 Long -81.3034150

    #Create 1 yak user that will get list of yaks. From here user selects the number yak that they want to me upvoted i amount of times
    remoteyakker = pk.Yakker(None, coordlocation, True)
    currentlist = remoteyakker.get_yaks()
    read(currentlist)
    print(
        "If you would like to upvote hack enter U and if you would like to downvote to delete enter D"
    )
    choice = input()

    if choice.upper() == 'U':
        #getList of yaks and print
        #input which yak to upvote hack
        yakID = int(input("Please enter the yak number from above: \n"))
        #input yikyak vote amount
        print("Enter the number of Yik Yak upvotes")
        numberOfVotes = int(input())

        #loop
        for num in range(0, int(numberOfVotes)):
            print(num)
            #creating a new yak user object with location at input
            remoteyakker = pk.Yakker(None, coordlocation, True)
            #Prints unique user id
            print("User ID: ", remoteyakker.id, "\n")
            #implement upvote
            #yaklist = remoteyakker.get_yaks()
            upvoted = remoteyakker.upvote_yak(currentlist[yakID -
                                                          1].message_id)
            if upvoted:
                print("\nUpvote successful :)")
            else:
                print("\nUpvote failed :(\t", end='')
                print(posted.status_code, end='')
                print(" ", end='')
                print(requests.status_codes._codes[posted.status_code][0])
    elif choice.upper() == 'D':
        #input which yak to upvote hack
        yakID = int(input("Please enter the yak number from above: \n"))
        numberOfLikes = int(
            input("Enter the number of likes the Yak currently has:"))
        for num in range(0, (numberOfLikes + 10)):
            remoteyakker = pk.Yakker(None, coordlocation, True)
            print("User ID: ", remoteyakker.id, "\n")
            #yaklist = remoteyakker.get_yaks()
            remoteyakker.downvote_yak(currentlist[yakID - 1].message_id)