Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- def main():
- userID = -1;
- if userID == -1:
- while True:
- try: userID = int(input("Enter User ID: ")); break;
- except: print("Invalid response.");
- print("Evaluating forum data from User ID: {}".format(userID));
- print("Analyzing last 200 posts...");
- times = [];
- for page in range(1,11):
- print("Analyzing posts {}-{}...".format((20*(page-1))+1, 20*page))
- fullUrl = "http://www.kongregate.com/users/{}/posts?page={}".format(userID, page);
- url = urllib.request.urlopen(fullUrl);
- urlString = url.read().decode(encoding='UTF-8');
- urlSplit = urlString.split("\n");
- count = 0;
- for index in range(len(urlSplit)):
- line = urlSplit[index];
- if "<abbr class=\"updated\"" in line:
- times.append(line[35:-2]);
- count += 1;
- if count == 0: break;
- if len(times) == 0: print("You don't have any forum posts."); return;
- hourDict = dict();
- for hour in range(24):
- hourDict[hour] = 0;
- for time in times:
- hour = time[11:-12];
- hourDict[int(hour)] += 1;
- print("\nPosts by hour (PDT):");
- for hour in sorted(hourDict):
- print("{:02d}: {}".format(hour, "x"*hourDict[hour]));
- minPost = 200;
- sumPosts = 0;
- sleep = 0;
- current = 0;
- for hour in sorted(hourDict):
- sumPosts = 0;
- current = hour;
- for nextHour in range(6):
- sumPosts += hourDict[current];
- if current == 23: current = 0;
- else: current += 1;
- if sumPosts < minPost:
- minPost = sumPosts;
- sleep = hour;
- print("\nYou sleep at around: {} o'clock (PDT).".format(sleep));
- if 0 < sleep < 20: print("Therefore, you are probably NOT an American!");
- else: print("Therefore, you probably ARE an American!");
- print("...Or you have terrible sleeping habits.");
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement