TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #121 · 20 јул.

Регулярно требуется преобразовать какой-либо текст в максимально совместимый текст для URL, имени файла, имени объекта в каком-то софте и тд. Требования совместимости простые: в тексте должны быть только допустимые символы. Обычно это a-z, 0-9 и "_" или "-". То есть, только прописные буквы латинского алфавита и цифры (как пример). Допустим, нам нужно название статьи в блоге преобразовать в slug для добавления его в URL этой статьи. Как это лучше всего сделать? В Django по умолчанию есть готовая функция slugify для таких случаев. Но я её никогда не использую. Почему? Потому что её недостаточно! Приведём пример >>> from django.utils.text import slugify >>> slugify('This is a Title') 'this-is-a-title' Пока всё отлично >>> slugify('This is a "Title!"') 'this-is-a-title' Спец символы удалились, всё хорошо. >>> slugify('Это заголовок статьи') '' Вот и приехали 😢. Если текст не английский то буквы просто игнорируются. Можно это поправить >>> slugify('Это заголовок статьи', allow_unicode=True) 'это-заголовок-статьи' Но тогда мы не вписываемся в условие. У нас появилась кириллица в тексте. Так как я часто пишу сайты для русскоязычных пользователей эта проблема весьма актуальна. Я не использую стандартную функцию и всегда пишу свою. Оригинал я не беру в расчёт и пишу полностью свою функцию. И так, по порядку: 🔸1. Исходный текст: >>> text = 'Мой заголовок №10 😁!' Взял специально посложней со специальными символами. 🔸2. Транслит Необходимо сделать транслит всех символов в латиницу. Здесь очень выручает библиотека unidecode. Помимо простого транслита кириллицы в латиницу она умеет преобразовывать спец символы и иероглифы в текстовые аналоги. from unidecode import unidecode >>> unidecode("Ñ Σ ® µ ¶ ¼ 月 山") 'N S (r) u P 1/4 Yue Shan' Очень крутая библиотека, советую👍 В нашем случае получаем такое преобразование: >>> text = unidecode(text) >>> print(text) 'Moi zagolovok No. 10 !' Отличный транслит. Смайл просто удалился, хотя я ждал что-то вроде :). Ну и ладно, всë равно невалидные символы. А еще наш код уже поддерживает любой язык, будь то хинди или корейский. 🔸4. Фильтр символов Unidecode не занимается фильтрацией по недопустимым символам. Это мы делаем в следующем шаге через regex. Просто заменим все символы на "_" если они вне указанного диапазона. >>> text = re.sub(r'[^a-zA-Z0-9]+', '_', text) >>> print(text) 'Moi_zagolovok_No_10_' Символ "+" в паттерне выручает когда несколько недопустимых символов идут рядом. Все они заменяются на один символ "_". 🔸5. Slugify Осталось удалить лишние символы по краям и сделать нижний регистр >>> text = text.strip('_').lower() >>> print(text) 'moi_zagolovok_no_10' Получаем отличный slug! 😎 🌎 Полный код в виде функции. ______________ PS. Проверку что в строке остался хоть один допустимый символ я бы вынес в отдельную функцию. #libs#tricks#django

Резултати

Пронајдени 68 слични објави

Пребарај: #qpr3

当前筛选 #qpr3清除筛选
Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #406 · 23.08.2024 г., 07:20

Bliss - Unofficial | Android 14 | Nothing Phone (2) ✍️ Details: - Version: 17.7 - Codename: #Pong - Released: 23/08/24 🔽 Download: [ GDrive ] (Sideload Build) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#Bliss#QPR3#U ✨ Changelogs - initial build ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - gapps already included 🏆 Credits - Chandu for base DT - Hellboy for Meteoric kernel - Fabian for PA Glyph Implementation - Testers 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #417 · 31.08.2024 г., 17:24

MistOS - UNOFFICIAL | A14 | Nothing Phone (2) 📔 Details: - Version: 2.8 - Codename: #Pong - Released: 31/08/2024 🔽 Download (Recovery) : Vanilla | Gapps (PL) | Gapps (L3) ⚙️ Installation: Here 📸 Screenshots: Here 🆘 Support: Telegram 🔖 Tags : #ROM#AOSP#UnOfficial#AOSP#QPR3#U#NothingPhone2 ✍️ Changelogs: - First Signed Build ✍️ Note: - Check Screenshots for features available - GKI Kernel is prepatched with KSU (Download Manager) - Clean flashing is mandatory - Flash Gapps 🏆 Credits - Chandu for base device tree & Kernel - OC'D, Miki, Unluck & Ghost for all help - Fabian & Hellboy for PA Glyph Implementation - Testers 😎 Maintainers: @AgBKartikey 🔔 Updates: @NothingPhone2Updates 💬 Chat: @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #467 · 02.11.2024 г., 18:14

Project Matrixx - Official | Android 14 | Nothing Phone (2) ✍️ Details: - Version: 10.9.1 - Codename: #Pong - Released: 02/11/24 🔽 Download: [ Sourceforge ] (Sideload/Flash via orangefox recovery) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#Official#Matrixx#QPR3#U ✨ Changelogs - Improvements to performance and system stability ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - Both Gapps and Vanilla build available 🏆 Credits - Chandu for base DT - Hellboy for Meteoric kernel - Fabian for PA Glyph Implementation - Testers 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #460 · 25.10.2024 г., 12:38

Project Infinity X - Official | A14| Nothing Phone 2 (Pong) 📝 Details: - Version: v1.6 - Device: #Pong - Released: 25/10/24 ⬇️ Download: Here 📖 Changelogs: Device | Source 📔 Instructions: Here 🎄 Device tree : Here 🖼 Screenshot : Here | Here 🆘 Support: Device 🏷 Tags: #AOSP#ROM#InfinityX#U#QPR3#Official ✍️ Note: • Read changelogs • OTA available • Base firmware 2.6.0 is recommended • Dirty flash possible from previous build • Based on Qpr3 September Security Patch • Dolby Atmos available • Flash meteoric kernel for KSU support • Nik gapps recommend for vanilla version 🏆 Credits: - Chandu Dyavanapelli for DT Base - Hellboy for kernel tree - Fabian and Hellboy for Glyph Implementation 👤 Maintainer: @Ghosutox 🔔 Updates: @NothingPhone2Updates 🐙 Chat: @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #440 · 24.09.2024 г., 03:43

Project Matrixx - Official | Android 14 | Nothing Phone (2) ✍️ Details: - Version: 10.8.1 - Codename: #Pong - Released: 23/09/24 🔽 Download: [ Sourceforge ] (Sideload/Flash via orangefox recovery) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#Official#Matrixx#QPR3#U ✨ Changelogs - Add Device Extras (Wireless Powershare and USB-OTG) - Improvements to performance and system stability ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - Both Gapps and Vanilla build available 🏆 Credits - Chandu for base DT - Hellboy for Meteoric kernel - Fabian for PA Glyph Implementation - Testers 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #439 · 18.09.2024 г., 14:12

Project Matrixx - Official | Android 14 | Nothing Phone (2) ✍️ Details: - Version: 10.8.0 - Codename: #Pong - Released: 18/09/24 🔽 Download: [ Sourceforge ] (Sideload Build) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#Official#Matrixx#QPR3#U ✨ Changelogs - switched to user build - added systemui restart in power menu - stability improvements ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - Both Gapps and Vanilla build available 🏆 Credits - Chandu for base DT - Hellboy for Meteoric kernel - Fabian for PA Glyph Implementation - Testers 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #429 · 11.09.2024 г., 10:17

Project Infinity X - Official | A14| Nothing Phone 2 (Pong) 📝 Details: - Version: v1.5 - Device: #Pong - Released: 11/09/24 ⬇️ Download: Here 📖 Changelogs: Device | Source 📔 Instructions: Here 🎄 Device tree : Here 🖼 Screenshot : Here | Here 🆘 Support: Device 🏷 Tags: #AOSP#ROM#InfinityX#U#QPR3#Official ✍️ Note: • Read changelogs • Base firmware 2.6.0 is recommended • Dirty flash possible from previous build • Based on Qpr3 September Security Patch • Dolby Atmos available • Flash meteoric kernel for KSU support • Nik gapps recommend for vanilla version 🏆 Credits: - Chandu Dyavanapelli for kernel & DT Base - Fabian and Hellboy for Glyph Implementation 👤 Maintainer: @Ghosutox 🔔 Updates: @NothingPhone2Updates 🐙 Chat: @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #425 · 10.09.2024 г., 09:09

Project Matrixx - Official | Android 14 | Nothing Phone (2) ✍️ Details: - Version: 10.8.0 - Codename: #Pong - Released: 10/00/24 🔽 Download: [ Sourceforge ] (Sideload Build) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#Official#Matrixx#QPR3#U ✨ Changelogs - added charging control ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - Both Gapps and Vanilla build available 🏆 Credits - Chandu for base DT - Hellboyfor Meteoric kernel - Fabian and Hellboyfor PA Glyph Implementation - Testers 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #416 · 31.08.2024 г., 11:58

Project Matrixx - Official | Android 14 | Nothing Phone (2) ✍️ Details: - Version: 10.7.3 - Codename: #Pong - Released: 24/08/24 🔽 Download: [ Sourceforge ] (Sideload Build) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#Official#Matrixx#QPR3#U ✨ Changelogs - switch to Dolby ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - Both Gapps and Vanilla build available 🏆 Credits - Chandu for base DT - Hellboy for Meteoric kernel - Fabian for PA Glyph Implementation - Testers 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #410 · 27.08.2024 г., 07:03

Project Infinity X - Official | A14| Nothing Phone 2 (Pong) 📝 Details: - Version: v1.4 - Device: #Pong - Released: 27/08/24 ⬇️ Download: Here 📔 Instructions: Here 🎄 Device tree : Here 🖼 Screenshot : Here | Here 🆘 Support: Device 🏷 Tags: #AOSP#ROM#InfinityX#U#QPR3#Official ✍️ Note: • Initial official release • Base firmware 2.6.0 is recommended • Clean flash mandatory • Based on Qpr3 August Security Patch • Dolby Atmos available • Flash meteoric kernel for KSU support • Nik gapps recommend for vanilla version 🏆 Credits: - Chandu Dyavanapelli for kernel & DT Base - Fabian and Hellboy for Glyph Implementation 👤 Maintainer: @Ghosutox 🔔 Updates: @NothingPhone2Updates 🐙 Chat: @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #407 · 23.08.2024 г., 15:18

Project Matrixx - Official | Android 14 | Nothing Phone (2) ✍️ Details: - Version: 10.7.2 - Codename: #Pong - Released: 23/08/24 🔽 Download: [ Sourceforge ] (Sideload Build) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#Official#Matrixx#QPR3#U ✨ Changelogs - update to 10.7.2 ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - Both Gapps and Vanilla build available 🏆 Credits - Chandu for base DT - Hellboy for Meteoric kernel - Fabian for PA Glyph Implementation - Testers 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #403 · 18.08.2024 г., 17:09

Project Matrixx - Official | Android 14 | Nothing Phone (2) ✍️ Details: - Version: 10.7.1 - Codename: #Pong - Released: 18/08/24 🔽 Download: [ Sourceforge ] (Sideload Build) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#Official#Matrixx#QPR3#U ✨ Changelogs - update to 10.7.1 ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - Both Gapps and Vanilla build available 🏆 Credits - Chandu for base DT - Hellboy for Meteoric kernel - Fabian for PA Glyph Implementation - Testers 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

123•••56
ПретходнаСтраница 1 од 6Следна