Skip to content

Instantly share code, notes, and snippets.

def get_all_article():
# initialize
article_api = "https://alis.to/api/articles/recent?limit=100&page=%d"
result = []
page = 1
# データ取得
while True:
try:
raw_article_data = urlopen(article_api % page).read().decode("utf-8")
json_article_data = json.loads(raw_article_data)
import twitter
import os
from urllib.request import urlopen
from datetime import datetime
import twitter
import pandas as pd
import json
auth = twitter.OAuth(consumer_key = os.environ["COMSUMER_KEY"],
consumer_secret = os.environ["COMSUMER_SECRET"],
from urllib.request import urlopen
import json
from googlesearch import search
from bs4 import BeautifulSoup as bs
from gensim.models import word2vec
import numpy as np
from gensim.models import KeyedVectors
import MeCab
import pandas as pd
from datetime import datetime
from hashlib import sha256
class Node:
def __init__(self, data):
self.left = None
self.right = None
self.parent = None
self.sibling = None
self.position = None
self.data = data
class Node:
def __init__(self, data):
self.left = None
self.right = None
self.parent = None
self.sibling = None
self.position = None
self.data = data
self.hash = sha256(data.encode()).hexdigest()
class Tree:
def __init__(self, leaves):
self.leaves = [Node(leaf) for leaf in leaves]
self.layer = self.leaves[::]
self.root = None
self.build_tree()
def build_layer(self):
new_layer = []
def build_layer(self):
new_layer = []
if len(self.layer) % 2 == 1:
self.layer.append(self.layer[-1])
for i in range(0, len(self.layer), 2):
left = self.layer[i]
right = self.layer[i+1]
parent = Node(left.hash + right.hash)
def build_tree(self):
while len(self.layer) > 1:
self.build_layer()
self.root = self.layer[0].hash
def search(self, data):
target = None
hash_value = sha256(data.encode()).hexdigest()
for node in self.leaves:
if node.hash == hash_value:
target = node
return target
def get_pass(self, data):
target = self.search(data)
markle_pass = []
if not(target):
return
markle_pass.append(target.hash)
while target.parent:
sibling = target.sibling
markle_pass.append((sibling.hash, sibling.position))
target = target.parent