示例#1
0
文件: example.py 项目: kocsenc/pyak
import pyak

#This registers a new user.
#In practice, you will want to save and re-use a single user ID.
#The constructor can be called with an optional astring argument for user ID.
yakker = pyak.Yakker()

print "Registered new user with id %s" % yakker.id

ut = pyak.Location("35.943356", "-83.938699")

yakker.update_location(ut)

yaks = yakker.get_yaks()

for yak in yaks:
    yak.print_yak()
    comments = yak.get_comments()
    for comment in comments:
        print "    %s" % comment.comment
    print ""
示例#2
0
文件: example.py 项目: ibanmd/pyak
import pyak

#This registers a new user.
#In practice, you will want to save and re-use a single user ID.
#The constructor can be called with an optional astring argument for user ID.
yakker = pyak.Yakker()

print "Registered new user with id %s" % yakker.id

ut = pyak.Location("30.271542", "-81.507936")

yakker.update_location(ut)

yaks = yakker.get_yaks()

for yak in yaks:
    yak.print_yak()
    comments = yak.get_comments()
    for comment in comments:
        print "    %s" % comment.comment
    print ""
示例#3
0
def yak_to_dict(yak):
    yak_dict = copy.deepcopy(dict(yak.__dict__))
    yak_dict['client'] = yak.client.__dict__
    yak_dict['client'][
        'location'] = yak_dict['client']['location'].__dict__ if type(
            yak_dict['client']
            ['location']) != dict else yak_dict['client']['location']
    return yak_dict


# user_id='FFD35754D9024E83425053CB67B7C9D3'
# user_id='E76D6FF1E04E83C414E7771EF3CBBBCD'
yakker = pyak.Yakker()
print "New yakker registered with ID: %s" % yakker.id
locations = {"tech": pyak.Location(42.057796, -87.676634)}


@sched.scheduled_job('interval', seconds=10)
def timed_job():
    print "trying to get yaks.."
    yakker.update_location(locations['tech'])
    yaks = yakker.get_yaks()
    print "Found %d yaks" % len(yaks)
    for yak in yaks:
        yak.message_id = yak.message_id.replace("R/", "")
        if firebase.get('/yaks', yak.message_id): break
        result = firebase.put(url='/yaks',
                              name=yak.message_id,
                              data=yak_to_dict(yak),
                              headers={'print': 'pretty'})
示例#4
0
        latlongs = json.loads(nabes.read())

    return latlongs


latlongs = getNabes(Data._PATH_TO_NEIGHBORHOODS)
#latlongs = getNabes(Data._PATH_TO_TEST)

for k, v in latlongs.items():

    nabe_name = k
    borough = latlongs[k]['borough']
    nabe_latitude = latlongs[k]['geo'][0]
    nabe_longitude = latlongs[k]['geo'][1]

    location = pk.Location(nabe_latitude, nabe_longitude)
    yakk = pk.Yakker(None, location, False)
    yaks = yakk.get_yaks()

    for yak in yaks:

        comments = []
        these_comments = yak.get_comments()

        if these_comments:
            for this in these_comments:
                comments.append({
                    "comment": this.comment,
                    "time": this.time,
                    "likes": this.likes
                })