Skip to content

Instantly share code, notes, and snippets.

@donghee
Created March 19, 2011 10:19
Show Gist options
  • Save donghee/877375 to your computer and use it in GitHub Desktop.
Save donghee/877375 to your computer and use it in GitHub Desktop.
olleh.com 문자 전송 프로그램
# -*- coding: utf-8 -*-
#!/usr/bin/python
import urllib
import urllib2
import cookielib
import re
from ClientForm import ParseResponse
class SmsClient:
opener =None
def __init__(self, id, password):
self.opener = self.build_opener()
self.login_olleh(id,password)
def build_opener(self):
cookie_jar = cookielib.CookieJar()
cookie_handler = urllib2.HTTPCookieProcessor(cookie_jar)
handlers = cookie_handler
_opener = urllib2.build_opener(handlers)
_opener.cookie_jar = cookie_jar
urllib2.install_opener(_opener)
return _opener
def login_pass0(self, _id, _password):
loginurl = "https://login.qook.co.kr/login/loginauth.php"
data = {'loginid': _id ,
'ID':_id, 'PASSWORD':_password,
'ktdid':'10000015'
}
encoded_data = urllib.urlencode(data)
response = self.opener.open(loginurl, encoded_data)
return response
def login_olleh(self, _id,_password):
response = self.login_pass0( _id, _password)
for i in range(1,6):
response = self.login_pass(response, i)
response = self.login_pass6(response, _id)
self.login_pass7(response)
def login_pass(self, response, stage):
forms = ParseResponse(response, backwards_compat=False)
form = forms[0]
response = self.opener.open(form.click())
return response
def login_pass6(self, response,_id):
forms = ParseResponse(response, backwards_compat=False)
form = forms[0]
loginurl = "http://www.olleh.com/HTML/abiosReturn.asp?loginID="+_id+"&ktssoflag=1"
encoded_data = form._request_data()[1]
self.opener.open(loginurl, encoded_data)
return response
def login_pass7(self, response):
response = self.opener.open('http://zone.olleh.com/mobile/sms/SMSList.zone?menuid=151000')
return response
def send_sms(self, _from, _to, message):
_msg = unicode(message,'utf8').encode('euc-kr')
loginurl = "http://sms.zone.olleh.com/MegaSms/mobile/sms/sms_main.html"
data = {
'reserveData':'',
'emotrowid':'',
'message':_msg,
'myphone':_from,
'names':'',
'phonenos':_to,
}
encoded_data = urllib.urlencode(data)
response = self.opener.open(loginurl, encoded_data)
def check_sms(self):
remain_sms = re.compile(".*<span class=\"orange\">(.*)<\/span>.*")
sms_page = self.opener.open("http://sms.zone.olleh.com/MegaSms/mobile/sms/sms_main.html").read()
print 'Available SMS for this month: '+ remain_sms.findall(sms_page)[1]
id = 'xxxxxx'
password = 'xxxxxxx'
s = SmsClient(id,password)
s.send_sms( '01094370000', '01094370001', '테스트 메시지 입니다.')
s.check_sms()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment