Example #1
0
def api_login(sid, login = None, use_ini = True) : # Получение токена (Desktop приложение)
	url = 'https://oauth.vk.com/authorize'
	login_ini = 1
	
	if use_ini == True :
		account_settings = {}
		
		if settings.has_key(login) == True :
			account_settings = settings[login]
			
			if account_settings.has_key('token') == True :
				login_ini = 0
				token = account_settings['token']

	try:
		if login_ini == 0 and use_ini == True:
			if check_token(token) == True:
				print 'API: token in config'
				return token
			else :
				login_ini = 1
		
		if login_ini == 1 :
			if check_sid(sid) == False :
				print 'API: login error - bad sid'
				return False
			
			values = {
				'client_id' : app_id,
				'scope' : 524287,
				'response_type' : 'token'
				}
			
			headers = {
				'User-Agent' : useragent,
				'Cookie' : 'remixsid=%s' % (sid)
				}
			
			data = urllib.urlencode(values)
			req = urllib2.Request(url, data, headers)
			response = urllib2.urlopen(req)
			res = response.read()
			geturl = response.geturl()
			
			if geturl != url :
				reg = 'access_token=(.*?)&'
			
				rg = re.compile(reg,re.IGNORECASE|re.DOTALL)
				m = rg.findall(geturl)
			
				if m:
					token=m[0]
					
					if token != None and check_token(token) == True :
						if use_ini == True :
							account_settings.update({'token' : token})
							settings.update({login : account_settings})
							cfg.update(settings)

						#print 'API: login'
						print 'login success'
						return token
			else :
				reg='\?hash=(.*?)&'
				rg = re.compile(reg,re.IGNORECASE|re.DOTALL)
				m = rg.findall(res)
				
				if m:
					hash = m[0]
					values = {
						'hash' : hash,
						'client_id' : app_id,
						'settings' : 524287,
						'redirect_uri' : 'blank.html',
						'response_type' : 'token'
						}
					url = 'https://api.vk.com/oauth/grant_access'
					
					data = urllib.urlencode(values)
					req = urllib2.Request(url + '?' + data, '', headers)
					response = urllib2.urlopen(req)
					res = response.read()
					geturl = response.geturl()
					
					reg = 'access_token=(.*?)&'
					rg = re.compile(reg,re.IGNORECASE|re.DOTALL)
					m = rg.findall(geturl)
					
					if m:
						token=m[0]
						
						if token != None and check_token(token) == True :
							if use_ini == True :
								account_settings.update({'token' : token})
								settings.update({login : account_settings})
								cfg.update(settings)

							#print 'API: login'
							print 'login success'
							return token
	except Exception, detail:
		print "def api_login:", detail
		e = raw_input('Error')
Example #2
0
def login(login, password, use_ini = True) : # Получение Cookies remixsid
	url_login = '******'
	login_ini = 1
	
	if use_ini == True :
		account_settings = {}
		
		if settings.has_key(login) == True :
			account_settings = settings[login]
			
			if account_settings.has_key('sid') == True :
				login_ini = 0
				sid = account_settings['sid']
	
	try:
		if login_ini == 0 and use_ini == True:
			if check_sid(sid) == True:
				#print 'VK: sid in config'
				print 'please wait...'
				return sid
			else :
				print 'VK: relogin'
				login_ini = 1
				
		if login_ini == 1 :
		
			values = {
				'act' : 'login',
				'email' : login,
				'pass' : password
				}

			headers = {
				'User-Agent' : useragent
				}
				
			cookie = cookielib.CookieJar()
			opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
			urllib2.install_opener(opener)

			data = urllib.urlencode(values)
			req = urllib2.Request(url_login, data, headers)
			response = urllib2.urlopen(req)
			res = response.read()

			reg = 'remixsid=(.*) for'
			rg = re.compile(reg,re.IGNORECASE|re.DOTALL)
			m = rg.findall(str(cookie))
			
			if m :
				sid = m[0]

				if sid != None and check_sid(sid) == True :
					if use_ini == True :
						account_settings.update({'sid' : sid})
						settings.update({login : account_settings})
						cfg.update(settings)

					print 'VK: login'
					return sid
				else :
					print 'VK: login error'
					return False
	
	except Exception, detail: 
		print "def login:", detail
		e = raw_input('Error')