示例#1
0
def post2Block(id, channel):
    c = client()
    c.setToken(w_token)

    post = c.retrievePost(id)

    title = post["title"]
    content = post["body"]

    data = {
        "content": content,
        "title": title,
    }

    try:
        uri = 'https://api.are.na/v2/channels/' + '%s/blocks' % channel

        r = requests.post(uri,
                          data=json.dumps(data),
                          headers={
                              "Authorization": "Bearer %s" % auth_token,
                              "Content-Type": "application/json"
                          })

    except Exception as e:
        print "Exception in createBlock: %s" % e
        return e

    return r.json()
示例#2
0
def w2n(url, id):
    # Setting up Notion client
    # Put in your token here
    token = ""
    client = NotionClient(token_v2=token)

    # Setting up Write.as client
    c = writeas.client()

    # Get Notion page url
    page = client.get_block(url)

    # Get Write.as post
    post = c.retrievePost(id)
    body = post['body']
    title = post['title']

    # Adds the Write.as post title to Notion page
    if title != '':
        page.children.add_new(SubheaderBlock, title=title)

# Add the Write.as post body to the Notion page by adding a new block
    new = page.children.add_new(TextBlock, title=body)

    return new
示例#3
0
def block2Post(id):
    c = client()
    c.setToken(w_token)

    block = getBlock(id)

    body = block['content']
    title = block['title']

    post = c.createPost(body, title)

    return post
示例#4
0
def update():
    # Grabs the RSS feed and converts the list of links into a string
    list = read(feed)
    feed_body = convert(list)

    # Combines the intro with the list to form the body
    body = '{}\n\n{}'.format(intro, feed_body)

    c = writeas.client()
    c.setToken(token)

    p = c.retrieveCPost(alias, slug)
    id = p['id']
    current_body = p['body']

    # Here is the code in the fxn that updates the post as the RSS feed updates
    # But if the RSS feed body and current body are the same, just spit out the post
    if current_body != body:
        c.updatePost(id, body=body)

    url = 'https://write.as/{}/{}'.format(alias, slug)

    return url
示例#5
0
文件: w2d.py 项目: cjeller1592/Dat.as
import writeas
import os
import json

# SET UP BEFORE RUNNING
# Add name of Write.as blog here (for ex: '365-rfcs' for 'https://write.as/365-rfcs')
collection = ''
# Add the complete folder path to your Dat blog here (for ex: '/Users/cjeller/Sites/365-rfcs-test')
path = ''

# Then the write.as business logic begins
c = writeas.client()

list = []

# I assume 200 posts is more than generous!
for i in range(1, 20):
    # Iterate through the pages...
    cposts = c.retrieveCPosts(collection, i)
    posts = cposts['posts']
    # If the posts are not an empty list, take each post and put it in a list!
    # That way it catches pages that don't have 10 posts
    if posts != []:
        for post in posts:
            # Append to the list of posts
            list.append(post)
    else:
        break
# This is so that when each post added to the posts.md file, it will appear in chronological order
list.reverse()