#!/usr/bin/env python
import ConfigParser
import json
import urllib
from urllib import urlopen

import logging
logging.basicConfig(filename='localization.log',level=logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')

config = ConfigParser.ConfigParser()
config.read('localization.ini')
url = 'http://ipinfo.io/json'
response = urlopen(url)
data = json.load(response)

IP = data['ip']
org = data['org']
city = data['city']
country = data['country']
region = data['region']

message = "Your vpn conection is broken please recconect " + country + " " + IP + " " + city + " " + org + " " + region

if country == 'PL':
    message = urllib.urlopen(
        "https://api.telegram.org/bot" +
        config.get('DEFAULT', 'telegramApiKey') +
        "/sendMessage?chat_id=" +
        config.get('DEFAULT', 'telegramUsername') +
        "&text=" + message
        ).read()

@@ -88,17 +88,16 @@
 urlopen%0A
-%0A
 import l
@@ -107,283 +107,578 @@
 ing%0A
+from 
 logging
-.basicConfig(filename='localization.log',level=logging.INFO)%0Aformatter = logging.Formatter('%25(asctime)s - %25(name)s - %25(levelname)s - %25(message)s')%0Alogging.debug('This message should go to the log file')%0Alogging.info('So should this')%0Alogging.warning('And this, too')%0A%0A
+ import handlers%0A%0Aclass LocalizationSender:%0A    logger = logging.getLogger('LocalizationSender')%0A    logger.setLevel(logging.DEBUG)%0A    handler = logging.handlers.RotatingFileHandler('localization.log', maxBytes=1000000, backupCount=5)%0A    logger.addHandler(handler)%0A    formatter = logging.Formatter('%25(asctime)s - %25(name)s - %25(levelname)s - %25(message)s')%0A    handler.setFormatter(formatter)%0A    MESSAGE = %22Your vpn conection is broken please recconect. %22%0A%0A    def messageLogger(self, text):%0A        self.logger.info(text)%0A%0A    def getConfig(self):%0A        
 conf
@@ -710,16 +710,24 @@
 arser()%0A
+        
 config.r
@@ -750,16 +750,82 @@
 n.ini')%0A
+        return config%0A%0A    def getLocalizationJSON(self):%0A        
 url = 'h
@@ -846,16 +846,24 @@
 o/json'%0A
+        
 response
@@ -882,14 +882,22 @@
 rl)%0A
-data =
+        return
  jso
@@ -918,181 +918,162 @@
 e)%0A%0A
-IP = data%5B'ip'%5D%0Aorg = data%5B'org'%5D%0Acity = data%5B'city'%5D%0Acountry = data%5B'country'%5D%0Aregion = data%5B'region'%5D%0A%0Amessage = %22Your vpn conection is broken please recconect %22 + 
+    def getTelegramMessage(self):%0A        data = self.getLocalizationJSON()%0A        self.messageLogger(data)%0A        return self.MESSAGE + data%5B'
 country
+'%5D
  + %22
@@ -1081,62 +1081,117 @@
 %22 + 
-IP + %22 %22 + city + %22 %22 + org + %22 %22 + region%0A%0Aif 
+data%5B'ip'%5D + %22 %22 + data%5B'city'%5D%0A%0A%0A    def sendMessage(self):%0A        if self.getLocalizationJSON()%5B'
 country
+'%5D
  == 
@@ -1196,16 +1196,112 @@
 = 'PL':%0A
+            message = self.getTelegramMessage()%0A            self.messageLogger(message)%0A        
     mess
@@ -1322,16 +1322,20 @@
 rlopen(%0A
+    
         
@@ -1367,38 +1367,52 @@
 /bot%22 +%0A        
-c
+    self.getC
 onfig
+()
 .get('DEFAULT', 
@@ -1439,16 +1439,20 @@
         
+ 
+   
 %22/sendMe
@@ -1477,22 +1477,36 @@
         
-c
+    self.getC
 onfig
+()
 .get('DE
@@ -1543,16 +1543,20 @@
         
+    
 %22&text=%22
@@ -1574,16 +1574,20 @@
         
+   
+ 
 ).read()
@@ -1587,8 +1587,84 @@
 .read()%0A
+%0AlocalizationSender = LocalizationSender()%0AlocalizationSender.sendMessage()%0A

Change localization.py structure