import collections
from src.DBmanage import DBmanage


class PTTpushAnalyser:

    def __init__(self):
        db = DBmanage()

    def analyse(self):
        pass

    def getAllAuthorPusherPairs(self, crawlArticles):
        allAuthorPusherPairs = []
        for artical in crawlArticles:
            authorID = artical['authorID']
            for push in artical['pushMessages']:
                pushUserID = push['pushUserID']
                pushTag = push['pushTag']
                authorPusherPair = (authorID, pushUserID, pushTag)
                allAuthorPusherPairs.append(authorPusherPair)

        return allAuthorPusherPairs

    def filterAuthorPusherPair(self, authorPusherPair):
        minDegree = 2
        pairSummary = collections.Counter(authorPusherPair)
        return [x for x in pairSummary if pairSummary[x] >= minDegree]

@@ -12,16 +12,38 @@
 ections%0A
+import networkx as nx%0A
 from src
@@ -864,8 +864,291 @@
 Degree%5D%0A
+%0A    def createNetworkGraph(self, authorPusherPair):%0A        graph = nx.DiGraph()%0A        for pair in authorPusherPair:%0A            author = pair%5B0%5D%0A            pusher = pair%5B1%5D%0A            graph.add_edge(pusher, author)%0A%0A        nx.draw(graph, with_labels=True, font_color='green')%0A

implement createNetworkGraph()