Exemplo n.º 1
0
def bridgy_twitter(location):
    """send a twitter mention to brid.gy"""
    if location.startswith('/e/'):
        location = location[3:]

    url = 'https://' + DOMAIN_NAME + "/e/" + location

    r = send_mention(url,
                     'https://brid.gy/publish/twitter',
                     endpoint='https://brid.gy/publish/webmention')
    syndication = r.json()
    print("\n\n\n {0} \n\n\n".format(url))
    data = file_parser_json('data/' + location + ".json", md=False)
    old_entry = data
    if data['syndication']:
        print syndication
        if type(data['syndication']) is unicode:
            data['syndication'] = data['syndication'].split(',')
        data['syndication'].append(syndication['url'])
    else:
        try:
            data['syndication'] = [syndication['url']]
        except KeyError:
            raise KeyError("There was no url! {0}".format(syndication))
    data['twitter'] = {'url': syndication['url'], 'id': syndication['id']}
    update_json_entry(data=data, old_entry=old_entry, g=None)
Exemplo n.º 2
0
def show_draft(name):
    if request.method == 'GET':
        if not session.get('logged_in'):
            abort(401)
        draft_location = 'drafts/' + name + ".json"
        entry = get_post_for_editing(draft_location)
        return render_template('edit_entry.html', entry=entry, type="draft")

    if request.method == 'POST':
        if not session.get('logged_in'):
            abort(401)
        data = post_from_request(request)

        if "Save" in request.form:  # if we're updating a draft
            file_name = "drafts/{0}".format(name)
            entry = file_parser_json(file_name + ".json")
            update_json_entry(data, entry, g=g, draft=True)
            return redirect("/drafts")

        if "Submit" in request.form:  # if we're publishing it now
            location = add_entry(request, draft=True)
            if os.path.isfile(
                    "drafts/" + name +
                    ".json"):  # this won't always be the slug generated
                os.remove("drafts/" + name + ".json")
            return redirect(location)
Exemplo n.º 3
0
def edit(year, month, day, name):
    """ The form for user-submission """
    app.logger.info(request)
    if request.method == "GET":
        try:
            file_name = "data/{year}/{month}/{day}/{name}".format(year=year, month=month, day=day, name=name)
            entry = file_parser_json(file_name + ".json", md=False)
            try:
                entry['category'] = ', '.join(entry['category'])
            except TypeError:
                entry['category'] = ''
            return render_template('edit_entry.html', entry=entry)
        except IOError:
            return redirect('/404')

    elif request.method == "POST":
        if not session.get('logged_in'):
            abort(401)
        app.logger.info(request.form)

        if "Submit" in request.form:
            data = post_from_request(request)
            if data['location'] is not None and data['location'].startswith("geo:"):
                (place_name, geo_id) = resolve_placename(data['location'])
                data['location_name'] = place_name
                data['location_id'] = geo_id

            location = "{year}/{month}/{day}/{name}".format(year=year, month=month, day=day, name=name)

            if request.form.get('twitter'):

                t = Timer(30, bridgy_twitter, [location])
                t.start()

            if request.form.get('facebook'):
                t = Timer(30, bridgy_facebook, [location])
                t.start()
            file_name = "data/{year}/{month}/{day}/{name}".format(year=year, month=month, day=day, name=name)
            entry = file_parser_json(file_name+".json")
            update_json_entry(data, entry, g=g)
            return redirect("/e/"+location)
        return redirect("/")
Exemplo n.º 4
0
def update_entry(update_request, year, month, day, name, draft=False):
    data = post_from_request(update_request)
    if data['location'] is not None and data['location'].startswith("geo:"):
        # get the place name for the item in the data.
        (place_name, geo_id) = resolve_placename(data['location'])
        data['location_name'] = place_name
        data['location_id'] = geo_id

    location = "{year}/{month}/{day}/{name}".format(year=year,
                                                    month=month,
                                                    day=day,
                                                    name=name)
    data['content'] = run(data['content'], date=data['published'])

    file_name = "data/{year}/{month}/{day}/{name}".format(year=year,
                                                          month=month,
                                                          day=day,
                                                          name=name)
    entry = file_parser_json(file_name + ".json",
                             g=g)  # get the file which will be updated
    update_json_entry(data, entry, g=g, draft=draft)
    syndicate_from_form(update_request, location, data['in_reply_to'])
    return location
Exemplo n.º 5
0
def show_draft(name):
    if request.method == 'GET':
        draft_location = 'drafts/' + name + ".json"
        entry = file_parser_json(draft_location, md=False)
        if entry['category']:
            entry['category'] = ', '.join(entry['category'])
        return render_template('edit_draft.html', entry=entry)

    if request.method == 'POST':
        if not session.get('logged_in'):
            abort(401)
        data = post_from_request(request)

        if "Save" in request.form:                          # if we're updating a draft
            file_name = "drafts/{0}".format(name)
            entry = file_parser_json(file_name+".json")
            location = update_json_entry(data, entry, g=g, draft=True)
            return redirect("/drafts")

        if "Submit" in request.form:                        # if we're publishing it now
            data['published'] = datetime.now()

            location = create_json_entry(data, g=g)
            if data['in_reply_to']:
                send_mention('http://' + DOMAIN_NAME +location, data['in_reply_to'])

            if request.form.get('twitter'):
                t = Timer(30, bridgy_twitter, [location])
                t.start()

            if request.form.get('facebook'):
                t = Timer(30, bridgy_facebook, [location])
                t.start()

            if os.path.isfile("drafts/"+name+".json"):           # this won't always be the slug generated
                os.remove("drafts/"+name+".json")

            return redirect(location)