Showing posts with label blogger. Show all posts
Showing posts with label blogger. Show all posts

Thursday, March 21, 2019

透過 Python 程式修改網誌文章

使用 Google Blogger API 可以利用程式修改網誌文章內容. http://mde.tw/cd2019

執行以下程式, 需要擷取 client_secrets.json 權限資料. 參考 https://developers.google.com/api-client-library/python/guide/aaa_client_secrets, 從  https://console.developers.google.com/apis/credentials 取得 client_secrets.json

可攜程式系統執行前, 必須額外安裝:

pip install google-api-python-client

pip install oauth2client

__author__ = 'disk1 At goodkym.com'

import sys
from oauth2client import client
from googleapiclient import sample_tools

argv = ""
# 認證並建立服務
service, flags = sample_tools.init(
  argv, 'blogger', 'v3', __doc__, __file__,
  scope='https://www.googleapis.com/auth/blogger')

try:
    users = service.users()
    # 取得使用者 profile 資料
    user = users.get(userId='self').execute()
    print('網誌名稱: %s' % user['displayName'])
    blogs = service.blogs()
    # 取得使用者所建立網誌名稱
    blogs = blogs.listByUser(userId='self').execute()
    for blog in blogs['items']:
        print(blog['name'], blog['url'])
    posts = service.posts()
    # 新增網誌 post 時, 需要 blog id
    '''
    body = {
    "kind": "blogger#post",
    "id": "5276710004996457925",
    "title": "透過 Python 程式新增網誌文章",
    "content":"使用 Google Blogger API 可以利用程式新增網誌文章內容"
    }
    insert = posts.insert(blogId='5276710004996457925', body=body)
    posts_doc = insert.execute()
    print(posts_doc)
    '''
    # 更新網誌文章時的 body
    body = {
    "kind": "blogger#post",
    "title": "透過 Python 程式修改網誌文章",
    "content":'''使用 Google Blogger API 可以利用程式修改網誌文章內容. http://mde.tw/cd2019
    '''
    }
    update = posts.update(blogId="5276710004996457925", postId="1389587938059038064", body=body, publish=True)
    update_doc = update.execute()
    print(update_doc)
except(client.AccessTokenRefreshError):
    print("error")
    
參考資料

Wordpress 與 Pelican 整合方案

Thursday, February 28, 2019

擦亮年輕人的網際內容名牌

這裡所謂年輕人的網際內容名牌, 指的是 Github 帳號, 網誌與 https://www.linkedin.com/.

Github 帳號可以呈現所執行專案的歷程細節資料, 而網誌可以是放在 Github Pages 上的靜態網誌, 也可以是 Google Blogger 等動態網誌, 表現的是個人在學習過程或執行專案歷程, 所逐一發表的重點註記、心得或觀點.

而 https://www.linkedin.com/ 則可視為您的專業履歷表.

Monday, February 25, 2019

多作者 Blogger

新增 Blogger 作者

根據 https://www.bloggingden.com/google-blogger-limitations/, 一個 Google blogger 最多只能邀
請 100 名協同作者.



進入 Blogger 中的

設定-基本-網誌作者

可以透過使用者電子郵箱, 邀請多人參與網誌著作, 可以邀請其他用戶擔任作者或管理員, 管理員可以管理網誌設定並編修所有網誌文章, 但是各作者只能編輯個人的文章.

四技一網際內容管理課程共用網誌: https://mde2019.blogspot.com/

五專一網際內容管理課程共用網誌: https://pmenfu.blogspot.com/

同時新增多名作者

在 Google Blogger 新增作者時, 需要在新增作者欄位填入電子郵箱, 若要同時邀請一個以上的作者, 則在各 email address 後面, 加上逗點隔開.

以下為處理上述兩個課程共用網誌作者時, 讀進修課人員名單, 然後附加 @gm.nfu.edu.tw 後, 同時新增 39 與 51 名作者.

filename = "wcm1aw1_student_list.txt"
with open(filename) as f:
    # 讀進全部檔案, 轉進數列, 並同時將各行的 \n 去除
    read_data = f.read().splitlines() 
for i in range(len(read_data)):
    print(str(read_data[i]) + "@gm.nfu.edu.tw, ")

四技一第一週修課人員名單: https://raw.githubusercontent.com/mdecourse/wcm2019/gh-pages/data/wcm1a/wcm1aw1_student_list.txt

五專一第一週修課人員名單: https://raw.githubusercontent.com/mdecourse/wcm2019/gh-pages/data/wcmj1a/wcmj1aw1_student_list.txt

NX12

NX 12 Help https://docs.plm.automation.siemens.com/tdoc/nx/12/nx_help Python related https://docs.plm.automation.siemens.com/tdoc/nx/...