2014년 6월 28일 토요일

[c#]1분 간격으로 이벤트 실행

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Timers;

namespace sendgmail
{
    public partial class Form1 : Form
    {
        static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
       
        public Form1()
        {
            InitializeComponent();

            timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
            timer.Interval = 60 * 1000;
            timer.Enabled = true;                       // Enable the timer
            timer.Start();    

  
        }

        // 쓰레드풀의 작업쓰레드가 지정된 시간 간격으로
        // 아래 이벤트 핸들러 실행
        private void timer_Tick(object sender, EventArgs e)
        {
            // MessageBox.Show("timer success");

        }

    }
}

2014년 6월 26일 목요일

윈도우환경에서 autoconf 사용

mingw32를 다운받고 installer에서 msys를 선택한 후 설치한다.

명령프롬프트에서 bash 입력

./configure 명령을 사용할 수 있다.

2014년 6월 25일 수요일

서브버전 사용법

서브버전 클라이언트를 설치
http://sourceforge.net/projects/win32svn/


명령프롬프트에서

svn checkout [주소]

2014년 6월 3일 화요일

get naver kin

use LWP::UserAgent;
use autodie qw/ open close /;
use WWW::Mechanize;
use LWP::Simple qw($ua get);
use Encode;

$filename="naverkin-phy.txt";
if(-e $filename)
    {
        unlink($filename);
    }

$ua->agent('My agent/1.0');

# create WWW::Mechanize object
# autocheck 1 checks each request to ensure it was successful
my $mech = WWW::Mechanize->new();

$mech->get("http://kin.naver.com/qna/list.nhn?m=noanswer&dirId=1114&page=1");
#$no=197187698;


$list_cont = $mech->content();

$list_cont=encode("euc-kr", $list_cont);
#print $list_cont;

@link = split(/docId=(\d{9})/, $list_cont);


for ($i=1; $i<=$#link; $i++){
    if ($i%2 == 1){
     push(@no, $link[$i]);
    }
}

@no = sort {$a <=> $b} @no;  # 1,2,3 순으로 정렬; Ascending
 
for ($i=1; $i<=$#no; $i++){

print $no[$i]." article is extracted...\n";

# paste from url of webbrowser manually later modify
$mech->get("http://kin.naver.com/qna/detail.nhn?d1id=11&dirId=1114&docId=$no[$i]");

$cont = $mech->content();
$cont=encode("euc-kr", $cont);

#@temp = split(/og:url/, $cont);
#@temp = split(/science&no=/, $temp[1]);
#@temp = split(/&page/, $temp[1]);


@temp = split(/tit_cont/, $cont);
@temp = split(/recom_q/, $temp[1]);
@temp = split(/img/, $temp[0]);
@temp = split(/dl/, $temp[0]);

$subject = $temp[0];
$subject =~ s/">//g;
$subject =~ s/h3>//g;
$subject =~ s/<//g;
$subject =~ s/\///g;
$subject =~ s/^\s+//g;
$subject =~ s/\s+$//g;

$subject = "subject: ".$subject;


@temp = split(/tit_cont/, $cont);
@temp = split(/recom_q/, $temp[1]);
@temp = split(/<dl>/, $temp[0]);
@temp = split(/<\/dl>/, $temp[1]);
@temp = split(/<dt>/, $temp[0]);
@temp = split(/<\/dt>/, $temp[1]);

$name = $temp[0];

$name =~ s/^\s+//g;
$name =~ s/\s+$//g;
$name = "name: ".$name;


@temp = split(/본문/, $cont);
@temp = split(/게시중단 안내/, $temp[3]);
$out = $temp[1];
$out =~ s/!<--$//;
$out =~ s/<\/div>//;
$out =~ s/\!<--//;
$memo = $out;

#print $memo;

$memo = "memo: ".$memo;

@temp = split(/본문/, $cont);
@temp = split(/게시중단 안내/, $temp[3]);
@img_url = split(/src="/,$temp[1]);
@img_url = split(/\?type/,$img_url[1]);
#print $img_url[0];

$img_url[0]=~ m/jpg|png|JPG|PNG/;

if ($img_url[0]){
$img_type = $&;
$mech->mirror($img_url[0], $no.".".$img_type);
}

$attached = "file:".$no.".".$img_type;

open MYFILE, ">>", "naverkin-phy.txt" or die ;
 print MYFILE "$no[$i]";
 print MYFILE "------------------------------------------------------------------------------\n";
 print MYFILE "$name\n";
 print MYFILE "$subject\n";
 print MYFILE "$memo\n";
 print MYFILE "$attached\n";

}

get bgm from bgmstore

use LWP::UserAgent;
use autodie qw/ open close /;
use WWW::Mechanize;
use LWP::Simple qw($ua get);
use Encode;

$ua->agent('My agent/1.0');

# create WWW::Mechanize object
# autocheck 1 checks each request to ensure it was successful
my $mech = WWW::Mechanize->new();

if (-e "bgmstore.txt"){
    unlink("bgmstore.txt");
    }
   
$mech->get("http://bgmstore.net/?q_type=category&q=%EC%9C%A0%EB%A8%B8");
@link = $mech->find_all_links( url_regex => qr/view/);

for $new_link (@link){
$url = $new_link->url_abs();

$no++;

if ($no % 2 == 0 ){
print $url;

$mech->get($url);
$cont = $mech->content();

print $no." article is extracted...\n";
@files=();

$cont=encode("euc-kr", $cont);

@temp = split(/titleBox/, $cont);
@temp = split(/<span/, $temp[1]);
$subject = $temp[0];
$subject =~ s/clearfix">//;

print $subject;
$name = "땡초";

@mp3 = $mech->find_all_links( url_regex => qr/mp3/);

print $mp3[0]->url_abs();
$filename = $subject;
$filename =~ s/,//g;
$filename =~ s/\?//g;
$filename =~ s/\s+//g;
print $filename;

$mech->mirror($mp3[0]->url_abs(), $filename.".mp3");


$name = "name: ".$name;
$subject = "subject: ".$subject;
$memo = "memo: ".$memo;

open MYFILE, ">>", "bgmstore.txt" or die ;
 print MYFILE "$no";
 print MYFILE "------------------------------------------------------------------------------\n";
 print MYFILE "$name\n";
 print MYFILE "$subject\n";
 print MYFILE "$memo\n";
 }
}