Example #1
0
def main(num):
    seeds = ['75007332', '1316932982', '261467131']
    #check init or restart
    if os.path.exists(path + "que_" + seeds[num - 1] + "_fr.pickle"):
        que_fr = load_pickle(path, "que_" + seeds[num - 1] + "_fr")
        que_fo = load_pickle(path, "que_" + seeds[num - 1] + "_fo")
    else:
        que_fr = seeds[num - 1]
        que_fr = seeds[num - 1]

    start_time = time.time()

    while (1):

        user = que.pop()

        print("user start : {0}".format(user))
        friend, follower = graph.update('all', user, 'nnn')

        for ad_fr in friend:
            flag = database.check(ad_fr)
            if flag != "protected" and flag != 'NotFound':
                que_fr.insert(0, ad_fr)

        for ad_fo in follower:
            flag = database.check(ad_fo)
            if flag != "protected" and flag != 'NotFound':
                que_fr.insert(0, ad_fr)

        end_time = time.time()

        if end_time - start_time > 1800:
            Mypickle.save(path, que_fr, "que_" + seeds[num - 1] + "_fr")
            Mypickle.save(path, que_fo, "que_" + seeds[num - 1] + "_fo")
            start_time = end_time
Example #2
0
def basic_pass1(seed):

  match_list = []

  friends = update("friends_only",seed, seed)
  if not os.path.isfile(DIR + seed + '_1.pickle'): Mypickle.save(DIR, friends, seed + '_1')

  return friends
Example #3
0
def basic_pass2(seed):

  match_list = []

  followers = update("followers_only",seed, seed)
  if not os.path.isfile(DIR + seed + '_2.pickle'): Mypickle.save(DIR, followers, seed + '_2')

  return followers
Example #4
0
def basic_pass7(seed):

  match_list = []


  friends, followers = update("all",seed,seed)
  if not os.path.isfile(DIR + seed + '_1.pickle'):  Mypickle.save(DIR, friends, seed + '_1')
  if not os.path.isfile(DIR + seed + '_2.pickle'):  Mypickle.save(DIR, followers, seed + '_2')
  match_list = list(set(followers) & set(friends))

  return match_list
Example #5
0
def basic_pass3(seed):

  match_list = []

  friends = update("friends_only",seed ,seed)
  if not os.path.isfile(DIR + seed + '_1.pickle'):  Mypickle.save(DIR, friends, seed + '_1')

  for friend in friends:
    followers = update("followers_only",friend, seed)
    match_list = list(set(match_list) | set(followers))

  if not os.path.isfile(DIR + seed + '_3.pickle'):  Mypickle.save(DIR, match_list, seed + '_3')
  return match_list
Example #6
0
def basic_pass4(seed):

  match_list = []


  followers = update("followers_only",seed, seed)
  if not os.path.isfile(DIR + seed + '_2.pickle'):  Mypickle.save(DIR, followers, seed + '_2')

  for follower in followers:
    friends = update("friends_only",follower, seed)
    match_list = list(set(match_list) | set(friends))

  if not os.path.isfile(DIR + seed + '_4.pickle'):  Mypickle.save(DIR, match_list, seed + '_4')
  return match_list
Example #7
0
def basic_pass17(seed):

  match_list = []
  frfr = []

  friends = update("friends_only", seed,seed)
  if not os.path.isfile(DIR + seed + '_1.pickle'):  Mypickle.save(DIR, friends, seed + '_1')

  for friend in friends:
    friends2friends = update("friends_only",friend,seed)
    frfr = list(set(friends2friends) & set(frfr))
    ans = list(set(friends) & set(friends2friends))
    match_list = list(set(match_list) | set(ans))

  if not os.path.isfile(DIR + seed + '_5.pickle'):  Mypickle.save(DIR, frfr, seed + '_5')
  return match_list
Example #8
0
def basic_pass11(seed):

  match_list = []

  friends, followers = update("all",seed,seed)
  if not os.path.isfile(DIR + seed + '_1.pickle'):  Mypickle.save(DIR, friends, seed + '_1')
  if not os.path.isfile(DIR + seed + '_2.pickle'):  Mypickle.save(DIR, followers, seed + '_2')

  mutual = list(set(followers) & set(friends))
  mutual = list(set(mutual) - set(seed))

  for m in mutual: ans = update("followers_only", m,seed)

  match_list = list(set(match_list) | set(ans))

  return match_list
Example #9
0
def basic_pass18(seed):

  match_list = []
  fofo = []

  followers = update("followers_only", seed,seed)
  if not os.path.isfile(DIR + seed + '_2.pickle'):  Mypickle.save(DIR, followers, seed + '_2')

  for follower in followers:
    followers2followers = update("followers_only",follower,seed)
    fofo = list(set(followers2followers) & set(fofo))
    ans = list(set(followers) & set(followers2followers))
    match_list = list(set(match_list) | set(ans))

  if not os.path.isfile(DIR + seed + '_3.pickle'):  Mypickle.save(DIR, fofo, seed + '_3')
  return match_list
Example #10
0
def basic_pass33(seed):

  match_list = []
  frfr = []
  frfo = []

  friends, followers  = update("all", seed,seed)
  if not os.path.isfile(DIR + seed + '_1.pickle'):  Mypickle.save(DIR, friends, seed + '_1')
  if not os.path.isfile(DIR + seed + '_2.pickle'):  Mypickle.save(DIR, followers, seed + '_2')

  for friend in friends:
    friends2friends, friends2followers = update("all",friend,seed)
    frfr = list(set(friends2friends) & set(frfr))
    frfo = list(set(friends2followers) & set(frfo))
    ans = list(set(followers) & set(friends) & set(friends2followers) & set(friends2followers))
    match_list = list(set(match_list) | set(ans))

  if not os.path.isfile(DIR + seed + '_5.pickle'):  Mypickle.save(DIR, frfr, seed + '_5')
  if not os.path.isfile(DIR + seed + '_3.pickle'):  Mypickle.save(DIR, frfo, seed + '_3')
  return match_list
Example #11
0
def basic_pass21(seed):

  match_list = []
  fofr = []

  friends, followers  = update("all", seed,seed)
  if not os.path.isfile(DIR + seed + '_1.pickle'):  Mypickle.save(DIR, friends, seed + '_1')
  if not os.path.isfile(DIR + seed + '_2.pickle'):  Mypickle.save(DIR, followers, seed + '_2')

  for follower in followers:
    followers2friends = update("friends_only",follower,seed)
    fofr = list(set(followers2friends) & set(fofr))
    ans = list(set(friends) & set(followers) & set(followers2friends))
    match_list = list(set(match_list) | set(ans))

  if not os.path.isfile(DIR + seed + '_4.pickle'):  Mypickle.save(DIR, fofr, seed + '_4')
  return match_list
Example #12
0
def personal_check(queryID, pattern, match_list, match_seeds, seeds_score):

    match_users = []

    for user in match_list:

        if len(
                database.select('SELECT * from query where userID = \'' +
                                user[0] + '\' AND queryID = \'' + queryID +
                                '\'')) != 0:
            continue

        responce = twitter.show(user[0])
        if responce.status_code != 200:
            print("Error code: %d" % (responce.status_code))
            continue

        ress = json.loads(responce.text)
        print("score : {0}".format(user[1]))
        print("\n\nhttps://twitter.com/intent/user?user_id=" + user[0])
        print(
            "screen_name:{0}\nuserID:{1}\nusername:{2}\nprofile:{3}\n".format(
                ress["screen_name"], user[0], ress["name"],
                ress["description"]))

        webbrowser_flag = False
        while (1):
            print("input true or false or half (help = h)")
            input_flag = input('>>>  ')
            '''if input_flag == "h":
        driver = webdriver.Chrome("./chromedriver")
        driver.get(":)
        webbrowser_flag = True

      elif input_flag == "y" or input_flag == "n":
        y_n[user] = input_flag
        if webbrowser_flag: driver.close()
        break'''

            if input_flag == "true":
                ID = database.select(
                    "SELECT MAX(ID) from query where queryID = \'" + queryID +
                    "\'")
                database.insert(
                    "query", (str(int(ID[0][0]) + 1), user[0], queryID, "2"))
                break
            elif input_flag == "false":
                ID = database.select(
                    "SELECT MAX(ID) from query where queryID = \'" + queryID +
                    "\'")
                database.insert(
                    "query", (str(int(ID[0][0]) + 1), user[0], queryID, "0"))
                break
            elif input_flag == "half":
                ID = database.select(
                    "SELECT MAX(ID) from query where queryID = \'" + queryID +
                    "\'")
                Mydatavase.insert(
                    "query", (str(int(ID[0][0]) + 1), user[0], queryID, "1"))
                break
            else:
                print("input again!!")

        print("{0} people checked!!".format(int(ID[0][0]) + 1))
        seeds = match_seeds[user[0]]
        if input_flag == "true":
            seeds_score = update_score(input_flag, pattern, seeds, seeds_score)
            seeds_score = init_score(user[0], seeds_score)
            match_users.append(user[0])
        else:
            seeds_score = update_score(input_flag, pattern, seeds, seeds_score)

        Mypickle.save(path, seeds_score, "seeds_score_" + queryID)

        continue_flag, next_pattern = passcheck_continue(pattern, seeds_score)
        if continue_flag is True or (continue_flag is False
                                     and input_flag == "true"):
            break

    return match_users, next_pattern, seeds_score
Example #13
0
        elif d == "old":
            d_flag = False
            break

    while (1):
        print("input queryID")

        queryID = input('>>> ')
        break

    print("queryID is {0}\n".format(queryID))
    c_flag = database.select("SELECT * from query where queryID = \'" +
                             queryID + "\'")
    if len(c_flag) > len(seeds_list):
        from mymodule import Mypickle
        seeds_score = Mypickle.load(path, "seeds_score_" + queryID)
        _, next_pattern = recommend.passcheck_continue("0", seeds_score)
        seeds_list = [i for i in seeds_score.keys()]

    else:
        seed_score = {p: [start_score, 0, 0, 0]
                      for p in path_pattern}  #[precision, good, bad]
        seeds_score = {i: seed_score for i in seeds_list}

        import random
        next_pattern = random.choice(path_pattern)
        for seed in seeds:
            database.insert("query", (0, seed, queryID, "None"))

    while (len(seeds_list) < get_num + start_num):
        next_pattern, seeds_list, seeds_score = recommend.recommendation(
Example #14
0
    SQL_match = database.select(
        "SELECT userID from query where queryID LIKE \'%" + queryID + "%\'" +
        "and result =  \'2\'")

    seeds = [s[0] for s in SQL_seeds]
    match = list(set([s[0] for s in SQL_match]))

    node2node = {
    }  #{userID:{friend:...,follower:...,friend2friend:...,friend2follower:...,follower2friend:...,follower2follower:...,}}
    nodeofflags = {}

    path = "../query/analysis/"
    pickle_path = "../pickle/positive/"
    doc_name = queryID + "_node2node"
    if os.path.exists(path + doc_name + ".pickle"):
        node2node = Mypickle.load(path, doc_name)
    print(len(node2node))

    print("seeds : {0}".format(seeds))
    print("match : {0}".format(match))

    for user in seeds + match:

        if user in node2node.keys(): continue

        node2node[user] = {}
        if user not in nodeofflags: nodeofflags[user] = [True, True]

        print("\nuser : {0} start".format(user))

        if nodeofflags[user][0] and nodeofflags[user][1]:
Example #15
0
def get_match(pattern, seeds):

  print("now : pattern{0}".format(pattern))

  from mymodule import Myyaml
  path_pattern = Myyaml.load("path")["path_com"]["39"]
  needs = Myyaml.load("path")["basic_path_com"][pattern]

  print("needs:{0}".format(needs))

  target_list = []
  target_seeds = {}

  for seed in seeds:
    print("graph {0}".format(seed))
    f = True
    for need in needs:
      if os.path.isfile(DIR + seed + '_' + need + '.pickle') == False:
          f = False
          break

    if f:
      print("all pickle")
      match_list = []
      for need in needs:
        su = Mypickle.load(DIR, seed + '_' +need)
        match_list = list(set(match_list) | set(su))

    else:
      print("else")
      if pattern == path_pattern[0]:#friend
        match_list = basic_pass1(seed)

      elif pattern == path_pattern[1]:#follower
        match_list = basic_pass2(seed)

      elif pattern == path_pattern[2]:#com_friend
        match_list = basic_pass3(seed)

      elif pattern == path_pattern[3]:#com_follower
        match_list = basic_pass4(seed)

      elif pattern == path_pattern[4]:#friend_friend
        match_list = basic_pass5(seed)

      elif pattern == path_pattern[5]:#follower_follower
        match_list = basic_pass6(seed)

      elif pattern == path_pattern[6]:#mutual
        match_list = basic_pass7(seed)

      elif pattern == path_pattern[7]:#8
        match_list = basic_pass8(seed)

      elif pattern == path_pattern[8]:#9
        match_list = basic_pass9(seed)

      elif pattern == path_pattern[9]:#10
        match_list = basic_pass10(seed)

      elif pattern == path_pattern[10]:#11
        match_list = basic_pass11(seed)

      elif pattern == path_pattern[11]:#12
        match_list = basic_pass12(seed)

      elif pattern == path_pattern[12]:#13
        match_list = basic_pass13(seed)

      elif pattern == path_pattern[13]:#14
        match_list = basic_pass14(seed)

      elif pattern == path_pattern[14]:#15
        match_list = basic_pass15(seed)

      elif pattern == path_pattern[15]:#16
        match_list = basic_pass16(seed)

      elif pattern == path_pattern[16]:#17
        match_list = basic_pass17(seed)

      elif pattern == path_pattern[17]:#18
        match_list = basic_pass18(seed)

      elif pattern == path_pattern[18]:#19
        match_list = basic_pass19(seed)

      elif pattern == path_pattern[19]:#20
        match_list = basic_pass20(seed)

      elif pattern == path_pattern[20]:#21
        match_list = basic_pass21(seed)

      elif pattern == path_pattern[21]:#22
        match_list = basic_pass22(seed)

      elif pattern == path_pattern[22]:#23
        match_list = basic_pass23(seed)

      elif pattern == path_pattern[23]:#24
        match_list = basic_pass24(seed)

      elif pattern == path_pattern[24]:#25
        match_list = basic_pass25(seed)

      elif pattern == path_pattern[25]:#26
        match_list = basic_pass26(seed)

      elif pattern == path_pattern[26]:#27
        match_list = basic_pass27(seed)

      elif pattern == path_pattern[27]:#28
        match_list = basic_pass28(seed)

      elif pattern == path_pattern[28]:#29
        match_list = basic_pass29(seed)

      elif pattern == path_pattern[29]:#30
        match_list = basic_pass30(seed)

      elif pattern == path_pattern[30]:#31
        match_list = basic_pass31(seed)

      elif pattern == path_pattern[31]:#32
        match_list = basic_pass32(seed)

      elif pattern == path_pattern[32]:#33
        match_list = basic_pass33(seed)

      elif pattern == path_pattern[33]:#34
        match_list = basic_pass34(seed)

      elif pattern == path_pattern[34]:#35
        match_list = basic_pass35(seed)
        match_seeds = join_dic([match_seeds])

      elif pattern == path_pattern[35]:#36
        match_list = basic_pass36(seed)

      elif pattern == path_pattern[36]:#37
        match_list = basic_pass37(seed)

      elif pattern == path_pattern[37]:#38
        match_list = basic_pass38(seed)

      elif pattern == path_pattern[38]:#39
        match_list = basic_pass39(seed)

      else:
        print("key error : {0}".format(pattern))
    print("match_list : {0}".format(len(match_list)))
    target_list = list((set(target_list) | set(match_list)))
    target_seeds = match(seed, match_list, target_seeds)

  return target_list, target_seeds
Example #16
0
def load_pickle(api):

    files = ['que_' + api]
    load_files = Mypickle.load(path, files)

    return load_files[0]
Example #17
0
def update(goal, userID, seed):

  friends = []
  followers = []
  flag = database.check(userID)

  if userID == seed:
    if goal == 'all':
      if os.path.isfile(DIR + seed + '_1' + '.pickle'):
          friends = Mypickle.load(DIR, seed + '_1')
      else:
          friends = up('friends_only', userID)
      if os.path.isfile(DIR + seed + '_2' + '.pickle'):
          followers = Mypickle.load(DIR, seed + '_2')
      else:
          followers = up('followers_only', userID)
      return friends, followers
    elif goal == 'friends_only':
      if os.path.isfile(DIR + seed + '_1' + '.pickle'): return Mypickle.load(DIR, seed + '_1')
    else:
      if os.path.isfile(DIR + seed + '_2' + '.pickle'): return Mypickle.load(DIR, seed + '_2')



  if goal == 'all':
    if flag == '***':
      friends = use_API(userID, 'friends')
      if friends is not None: database.select('UPDATE checked_list SET state = \'friends_only\' WHERE userID = \'{0}\''.format(userID))
      followers = use_API(userID, 'followers')
      if followers is not None: database.select('UPDATE checked_list SET state = \'all\' WHERE userID = \'{0}\''.format(userID))
    elif flag == 'followers_only':
      friends = use_API(userID, 'friends')
      followers = database.select('SELECT userID FROM follow_graph WHERE followerID = \'{0}\''.format(userID))
      followers = tuple2list(followers)
      if friends is not None: database.select('UPDATE checked_list SET state = \'all\' WHERE userID = \'{0}\''.format(userID))
    elif flag == 'friends_only':
      followers == use_API(userID, 'followers')
      friends = database.select('SELECT followerID FROM follow_graph WHERE userID = \'{0}\''.format(userID))
      friends = tuple2list(friends)
      if followers is not None: database.select('UPDATE checked_list SET state = \'all\' WHERE userID = \'{0}\''.format(userID))
    elif flag == "all":
      friends = database.select('SELECT followerID FROM follow_graph WHERE userID = \'{0}\''.format(userID))
      friends = tuple2list(friends)
      followers = database.select('SELECT userID FROM follow_graph WHERE followerID = \'{0}\''.format(userID))
      followers = tuple2list(followers)

    if friends is None or followers is None: return [], []
    return friends, followers

  elif goal == 'friends_only':
    if flag == 'followers_only':
      friends = use_API(userID, 'friends')
      if friends is not None: database.select('UPDATE checked_list SET state = \'all\' WHERE userID = \'{0}\''.format(userID))
    elif flag == '***':
      friends = use_API(userID, 'friends')
      if friends is not None: database.select('UPDATE checked_list SET state = \'friends_only\' WHERE userID = \'{0}\''.format(userID))
    elif flag == 'friends_only' or flag == 'all':
      friends = use_API(userID, 'friends')
      friends = database.select('SELECT followerID FROM follow_graph WHERE userID = \'{0}\''.format(userID))
      friends = tuple2list(friends)

    if friends is None: return []
    return friends

  elif goal == 'followers_only':
    if flag == 'friends_only':
      followers = use_API(userID, 'followers')
      if followers is not None: database.select('UPDATE checked_list SET state = \'all\' WHERE userID = \'{0}\''.format(userID))
    elif flag == '***':
      followers = use_API(userID, 'followers')
      if followers is not None: database.select('UPDATE checked_list SET state = \'followers_only\' WHERE userID = \'{0}\''.format(userID))
    elif flag == 'followers_only' or flag == 'all':
      followers = database.select('SELECT userID FROM follow_graph WHERE followerID = \'{0}\''.format(userID))
      followers = tuple2list(followers)

    if followers is None: return []
    return followers