Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
特定タグの付いたはてなブックマークを削除
#!/usr/bin/python
#-* coding:utf-8 -*-
import feedparser,sys,urllib
import json
import requests
from requests_oauthlib import OAuth1
def get_username(auth):
response = requests.get("http://api.b.hatena.ne.jp/1/my", auth=auth)
return json.loads(response.text)["name"]
def delete_bookmark(auth,url):
response = requests.delete('http://api.b.hatena.ne.jp/1/my/bookmark',params={"url": url}, auth=auth)
if response.status_code == 204:
print("delete:"+url)
else:
print("failed:"+url)
if __name__ == "__main__":
consumer_key = ""
consumer_secret = ""
access_token = ""
access_secret = ""
auth = OAuth1( consumer_key, consumer_secret, access_token, access_secret )
#消したいタグ(空白だと全部消えるので注意)
tag = "hogehoge"
username = get_username(auth)
feed_url = "http://b.hatena.ne.jp/"+username+"/atomfeed?tag="+urllib.parse.quote(tag)
while True:
feed = feedparser.parse(feed_url,request_headers={'Cache-control': 'max-age=0'})
if(len(feed['entries'])==0):
break
for entry in feed['entries']:
url = entry.links[0].href
delete_bookmark(auth,url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.