123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- from pydoc import HTMLDoc
- import dataset
- import sys
- import os
- import time
- import subprocess
- import suggests
- from typing import Optional
- import networkx as nx
- import pyvis
- import time
- from pyvis.network import Network
- import pickle
- import logging
- import threading
- import time
- import random
- import string
- def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
- return ''.join(random.choice(chars) for _ in range(size))
- def thread_function(kw):
- global db
- print(kw)
- G = nx.Graph()
- for k in kw:
- s = suggests.suggests.get_suggests(k, source='google')
- for sg in s['suggests']:
- G.add_edge(k,sg,weight=1)
- print(sg)
- time.sleep(1)
- s2 = suggests.suggests.get_suggests(k, source='google')
- for elmt in s2['suggests']:
- G.add_edge(sg,elmt,weight=1)
- # G.remove_nodes_from(list(nx.isolates(G)))
- G.remove_edges_from( list(nx.selfloop_edges(G)))
- # pickle.dump( G, open( "gs2.p", "wb" ) )
- pyG = Network(height="750px", width="100%",bgcolor="#333333",font_color="white")
- pyG.from_nx(G)
- id=id_generator()
- # db['gen_graph'].insert({'filename':str(id),'kw':str(kw)})
- # pyG.save_graph('gstest')
- # pyG.show('static/gs/'+str(id)+'.html')
- pyG.save_graph('static/gs/'+str(id)+'.html')
- thread_function('娛樂城')
|