[{"ID":"6F5F351E-9798-43F2-B612-58A97597F6A8","title":"Serveur de fichiers rapide en Python","tags":"astuce python","date":"19\/11\/2020","timestamp":"1605791878","rss_date":"Thu, 01 Jan 1970 01:00:00 +0100","status":"public","dependency":"","source":"","content":"Terminal depuis le dossier \u00e0 partager puis:\r\n(en Python 2) : python -m SimpleHTTPServer 5555\r\n(en Python 3) : python -m http.server 5555\r\net acc\u00e9dez avec un simple navigateur (http:\/\/adresseip:5555)"},{"ID":"D999BC20-5F89-47D4-9D3E-B470AA8940E9","title":"locale_load + trad","tags":"fichiers python texte","date":"13\/03\/2018","timestamp":"1520944388","rss_date":"Tue, 13 Mar 2018 13:33:08 +0100","status":"public","dependency":"","source":"http:\/\/warriordudimanche.net","content":"def locale_load(self,lang):\r\n\t\tlocale_file='sys\/locales\/'+lang+\".locale\"\r\n\t\tif not os.path.isfile(locale_file): \r\n\t\t\tself.locale={}\r\n\t\t\treturn\r\n\r\n\t\tlocale={}\r\n\t\tlocale_str=file_get_contents(locale_file)\r\n\t\tlocale_str=re.findall('\\\"(?P<eng>.*?)\\\"=\\\"(?P<trad>.*?)\\\"',locale_str)\r\n\t\tfor key,val in enumerate(locale_str):\r\n\t\t\tlocale[locale_str[key][0]]=locale_str[key][1]\r\n\t\tself.locale=locale\r\n\r\n# syntaxe du fichier locale\r\n#\"Title\"=\"Titre\",\r\n#\"Author\"=\"Auteur\",\r\n#\"Language\"=\"Langue\",\r\n\r\n\t\t\r\n\tdef trad(self,term):\r\n\t\tif not term in self.locale: \r\n\t\t\treturn term\r\n\t\treturn self.locale[term]"},{"ID":"10862D8D-96F4-476E-9F8F-F13A0ABED30B","title":"ini_load","tags":"fichiers fonctions python","date":"13\/03\/2018","timestamp":"1520944304","rss_date":"Tue, 13 Mar 2018 13:31:44 +0100","status":"public","dependency":"","source":"http:\/\/warriordudimanche.net","content":"\tdef ini_load(self,ini_file):\r\n\t\tif not os.path.isfile(ini_file): return false\r\n\t\tcfg={}\r\n\t\tini_str=file_get_contents(ini_file)\r\n\t\tini=re.findall('(?P<var>[a-zA-Z0-9_]*?)=\\\"(?P<value>[^\\\"]*?)\\\"',ini_str)\r\n\t\tfor key,val in enumerate(ini):\r\n\t\t\tcfg[ini[key][0]]=ini[key][1]\r\n\t\tself.cfg=cfg\r\n\t\t\r\n\r\n# syntaxe des variables\r\n# folder_path=\"test\/\""},{"ID":"4FC2130D-6EAE-41AE-9D6A-0B251A810C71","title":"no_accents","tags":"fonctions python texte","date":"13\/03\/2018","timestamp":"1520944227","rss_date":"Tue, 13 Mar 2018 13:30:27 +0100","status":"public","dependency":"","source":"http:\/\/warriordudimanche.net","content":"def no_accents(string):\r\n\treplacements=[\r\n\t\t(u\"\u00e9\",\"e\"),\r\n\t\t(u\"\u00ea\",\"e\"),\r\n\t\t(u\"\u00e8\",\"e\"),\r\n\t\t(u\"\u00eb\",\"e\"),\r\n\t\t(u\"\u00f4\",\"o\"),\r\n\t\t(u\"\u00f3\",\"o\"),\r\n\t\t(u\"\u00f9\",\"u\"),\r\n\t\t(u\"\u00fa\",\"u\"),\r\n\t\t(u\"\u00fb\",\"u\"),\r\n\t\t(u\"\u00fc\",\"u\"),\r\n\t\t(u\"\u00ee\",\"i\"),\r\n\t\t(u\"\u00ef\",\"i\"),\r\n\t\t(u\"\u00ed\",\"i\"),\r\n\t\t(u\"\u00e2\",\"a\"),\r\n\t\t(u\"\u00e0\",\"a\"),\r\n\t\t(u\"\u00e1\",\"a\"),\r\n\t\t(u\"\u00e4\",\"a\"),\r\n\t\t(u\"\u00f1\",\"n\")\r\n\t]\r\n\tfor a, b in replacements:\r\n\t\tstring = string.replace(a, b)\r\n\treturn string"},{"ID":"141A008C-78AC-4B93-8274-3FEFB4B82C30","title":"getDistantFile","tags":"fichiers python","date":"13\/03\/2018","timestamp":"1520944193","rss_date":"Tue, 13 Mar 2018 13:29:53 +0100","status":"public","dependency":"","source":"http:\/\/warriordudimanche.net","content":"import urllib\r\n# get_distant_file function\r\ndef get_distant_file(string):\r\n\t\r\n\ttry:\r\n\t\tdata=urllib.urlopen(string).read()\r\n\texcept:\r\n\t\tdata=\"\"\r\n\tfinally:\r\n\t\treturn data.encode('utf8')\r\n"},{"ID":"833135D2-F937-408F-986D-20EF6DB966B7","title":"striptags","tags":"python securite","date":"13\/03\/2018","timestamp":"1520944129","rss_date":"Tue, 13 Mar 2018 13:28:49 +0100","status":"public","dependency":"","source":"http:\/\/warriordudimanche.net","content":"# strip tags function\r\ndef striptags(string):\t\r\n\treturn re.sub(u\"<head>[^^]*?<\/head>|<[^>]*?>|&lt;[^>]*?&gt;|&nbsp;\",u\" \",string)\r\n"},{"ID":"5B1C7EA1-737D-49A8-9917-299903698832","title":"file_get_contents & file_put_contents","tags":"fichiers python","date":"13\/03\/2018","timestamp":"1520944100","rss_date":"Tue, 13 Mar 2018 13:28:20 +0100","status":"public","dependency":"","source":"http:\/\/warriordudimanche.net","content":"# file_get_contents function\r\ndef file_get_contents(filename):\r\n\tcontent=\"\"\r\n\tif not os.path.isfile(filename): return false\r\n\tf = open(filename, 'r')\r\n\ttry:\r\n\t\tcontent=f.read(1000000).decode('utf8')\r\n\tfinally:\r\n\t\tf.close()\r\n\treturn content\r\n\r\n# file_put_contents function\r\ndef file_put_contents(filename,data):\r\n\tif not os.path.isfile(filename): return false\r\n\tf = open(filename, 'w')\r\n\tf.write(data.decode('utf8'))\r\n\tf.close()"},{"ID":"77683D6C-91E9-4EA6-A357-900F49A4987C","title":"loadJson & saveJson","tags":"fichiers python","date":"13\/03\/2018","timestamp":"1520944069","rss_date":"Tue, 13 Mar 2018 13:27:49 +0100","status":"public","dependency":"","source":"http:\/\/warriordudimanche.net","content":"# saveJson function\r\ndef saveJson(filename,data):\r\n\tf = open(filename, 'w')\r\n\tf.write(json.dumps(data))\r\n\tf.close()\r\n\r\n# loadJson function\r\ndef loadJson(filename):\r\n\tif not os.path.isfile(filename): return false\r\n\tf = open(filename, 'r')\r\n\tcontent=f.read()\r\n\tif content==\"\":return {}\r\n\treturn json.loads(content)\r\n"},{"ID":"136080D0-EC73-4AFB-99B3-E9A8C9E620A6","title":"aff - python","tags":"python  debug","date":"13\/03\/2018","timestamp":"1520944033","rss_date":"Tue, 13 Mar 2018 13:27:13 +0100","status":"public","dependency":"","source":"http:\/\/warriordudimanche.net","content":"# aff(var)\r\ndef aff(var):\r\n\timport pprint\r\n\tpprint.pprint(var)"},{"ID":"02F6338B-97F4-437D-A44B-FD314CF6EC77","title":"file_get_contents-file_put_contents","tags":"python","date":"24\/02\/2018","timestamp":"1519480361","rss_date":"Sat, 24 Feb 2018 14:52:41 +0100","status":"public","dependency":"","source":"","content":"import os\r\n# file_get_contents function\r\ndef file_get_contents(filename):\r\n\tif not os.path.isfile(filename): return false\r\n\tf = open(filename, 'r')\r\n\treturn f.read()\r\n# file_put_contents function\r\ndef file_put_contents(filename,data):\r\n\tif not os.path.isfile(filename): return false\r\n\tf = open(filename, 'w')\r\n\tf.write(data)\r\n\tf.close()"},{"ID":"985F595E-7D20-4294-B81C-6A453D627097","title":"striptags","tags":"python","date":"24\/02\/2018","timestamp":"1519480347","rss_date":"Sat, 24 Feb 2018 14:52:27 +0100","status":"public","dependency":"","source":"","content":"import re\r\n# strip tags function\r\ndef striptags(self,string=\"\"):\r\n\t\treturn re.sub(\"<[^>]*?>|&lt;[^>]*?&gt;\",\"\",string)\r\n"}]