Header

  1. View current page

    노이쉬*^^*의 노트

Profile_img_60x60_01
0

미투데이 글 작성 시간을 분석해서 만든 그래프

미투데이 글 작성 시간을 분석해서 만든 그래프

 

미투데이에 지정한 페이지에 접속해서 글 작성한 시간을 뽑아서 데이타 파일로 만든 후

그래프 라이브러리를 이용하여 그려 보았다~  (심심해서...=ㅅㅜ)

심심해서 그려 보기는 했지만... 재미있다~   다음에는 뭐 그려볼까? ^^;

작성 시간을 보니... 오전 8시에서 오후 8시대에 많이 놀았구나-_-;;

좀 자제하고...  생산적인 일을 해보자 ㅎㅎㅎ ^^;

 

 2381798435_857728c90b.jpg

 

아래는 미투데이의 계정에 접속해서 날짜를 긁어 오는 소스=_=
urllib, sys, re, BeautifulSoup 라이브러리를 이용~

 

  1. #!/usr/bin/python

    import urllib
    import sys
    import re
    from BeautifulSoup import BeautifulSoup

    # user's account name
    account_name = 'lovenoish'
    me2day_url = 'http://me2day.net/'
    me2day_url = me2day_url + account_name
    fetch_page = urllib.urlopen(me2day_url).read()

    while(1):
        soup = BeautifulSoup(fetch_page)
       
        #cal_year
        cal_year = soup('span', {'class':'cal_year',})
        cal_year = re.search(r'>(\d*)<', str(cal_year)).group(1)

        #cal_month
        cal_month = soup('span', {'class':'cal_month',})
        cal_month = re.search(r'>([a-zA-Z]*)<', str(cal_month)).group(1).upper()
        cal_month_data = {'JAN':'1', 'FEB':'2', 'MAR':'3', 'APR':'4', 'MAY':'5', 'JUN':'6', 'JUL':'7', 'AUG':'8', 'SEP':'9', 'OCT':'10', 'NOV':'11', 'DEC':'12'}
        cal_month = cal_month_data.get(cal_month)

        #cal_day
        cal_day = soup('div', {'class':'cal_day',})
        cal_day  = re.search(r'>(\d*)<', str(cal_day)).group(1)

        # nextpage link
        nextpage_link = soup('li', {'id':'prev_list',})
        # In lastpage, attribute error why?
        me2day_url = "http://me2day.net" + re.search(r'href="(.*?)"', str(nextpage_link)).group(1)
       
        x = 0
        while(1):
            # time
            try:
                written_time = soup('a', {'rel':'bookmark',})[x]
            except IndexError:        
                try:
                    fetch_page = urllib.urlopen(me2day_url).read()
                    break # while break and go to the first While (Fetch nextpage)
                except NameError: # nextpage not exist so Program exit               
                    sys.exit()
                               
            written_time = str(written_time).split('#')
            written_time = str(written_time[1]).split("\"")
            written_time = str(written_time[0]).split(":")
            written_hour = written_time[0]
            written_minute = written_time[1]
            written_second = written_time[2]

            # need to modify
            if int(written_hour) < 12:
                written_ampm = 'am'
            else:
                written_ampm ='pm'
               
            print "data:" + written_hour + ":" + written_ampm       
            x = x + 1

 

아래는 긁어온 데이타를 기반으로 그래프를 그려주는 소스 ==)/

  1. #!/usr/bin/python

    import gdchart

    x = gdchart.Line()
    x.bg_color = 0xffffff
    x.width = 500
    x.height = 500
    x.xtitle = "Time"
    x.ytitle = "Value"
    x.title = "Me2day Graph"

    f = open("me2day_lovenoish_data.txt")
    line = f.readline()

    dataBox = []
    for tmpX in range(24):
        dataBox.append(0)
       
    while line:
        data_time = line.split(":")
        if data_time[0] == "data":       
            int_data_time = abs(int(data_time[1]))       
            dataBox[int_data_time-1] = dataBox[int_data_time-1] + 1                       
        line = f.readline()

    x.setData(dataBox)
    x.setLabels(["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23", "24"] )
    x.draw("simple.jpg")

 

그렇게 잘만든 코드는 아니지만... 나름 만족 ㅎㅎㅎ ^_^;

 

마지막으로... 본 소스를 돌리면 미투데이 해당 계정의 카운터가 정신 없이 올라 간다...-_-;;;

 

History

Last edited on 04/24/2008 17:55 by noish

Comments (0)

You must log in to leave a comment. Please sign in.