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

Резултати

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

Пребарај: #neoteric

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

@NothingPhone2Updates · Post #555 · 06.02.2025 г., 11:31

NeotericOS - CLO | Android 15 | Nothing Phone (2) ✍️Details: - Version: 15 - Device: #Pong - Released: 08/02/25 🔽 Download : ROM (Sideload) | Recovery 🆘 Support Group : Here 🔖 Tags : #Neoteric#V#CLO#ROM ✨Changelogs: • Updated to jan sec patch • Fixed an issue where alarm volume region was not touchable in volume panel • New brightness slider UI in QS • Updated play integrity fp • New aptx preferences UI (i can't remember if this was rolled out before) 📔 Notes: - Sideload using provided recovery only. - NOS 3.0 FW is recommended. - Meteoric Kernel with pre-patched KSU is included! 👤 Dev : @HELLBOY017 🔔 Updates : @NothingPhone2Updates 🐙 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #499 · 25.12.2024 г., 18:03

Neoteric OS | Android 15 | Nothing Phone (2) ✍️Details: - Version: 15 - Device: #Pong - Released: 25/12/2024 🔽 Download : [ Sourceforge (Recovery) | Fastboot ] Build ⚙️ Installation: Here 🆘 Support Group : Here 🔖 Tags : #Neoteric#V#CLO#ROM ✨Changelog:- • Merged clo system tag:- LA.QSSI.15.0.r1-13000-qssi.0 • Merged clo vendor tag:- LA.VENDOR.14.3.0.r1-18400-lanai.QSSI15.0 • Performance improvements in display hal • QS expand boost (should fix qs lag) • Use scalable grids in launcher (for less than 5 column grids) • Fix lens button crash in launcher search bar • Add circle to search toggle in launcher • More haptics improvements • Material3 switches for screen record options • Dexopt improvements ✍️ Note: - FW Required: NOS 2.6 / 3.0 - OTA has been pushed for users on previous build soon - Use Neoteric recovery for sideloading 🏆Credits: - Neoteric OS Team - Testers who helped all throughout 😎 Dev : @HELLBOY017 🔔 Updates : @NothingPhone2Updates 🐙 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #486 · 11.12.2024 г., 12:53

Neoteric OS | Android 15 | Nothing Phone (2) ✍️Details: - Version: 15 - Device: #Pong - Released: 11/12/2024 🔽 Download : Sourceforge ⚙️ Installation: Here 🆘 Support Group : Here 🔖 Tags : #Neoteric#V#CLO#ROM Changelog:- * Fix edge light custom color not applying * Update fingerprint to pass device integrity * Add haptics to more elements * Fix crash after enrolling fp if face unlock is enabled * Performance enhancements * Fix package cache related issues * Add overview scale animation in recents * Redesign Settings page 🏆Credits: - Neoteric OS Team - Testers who helped all throughout 😎 Dev : @HELLBOY017 🔔 Updates : @NothingPhone2Updates 🐙 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #474 · 18.11.2024 г., 11:13

Neoteric OS | Android 15 | Nothing Phone (2) 📔 Details: - Version: 15 - Device: #Pong - Inital Release : 06/12/24 🔽 Download : Sideload | Fastboot ⚙️ Installation: Here 🆘 Support Group : Here 🔖 Tags : #Neoteric#V#CLO#ROM ⚙️ Changelogs: - OTA updates via system would be pushed with future releases by the maintainer. Refer to changelogs from support chat. ✍️ Note: - Sideload via Neoteric Recovery for recovery build. Else use fastboot one - If you are facing any issues with booting fastboot build, flash super empty > fastboot -w > fastboot update <path to rom.zip> - Users on older build can update via in built system ota updater 🏆 Credits: - Neoteric OS Team - Testers who helped all throughout 😎 Dev : @HELLBOY017 🔔 Updates : @NothingPhone2Updates 🐙 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #450 · 17.10.2024 г., 04:34

Neoteric OS | Android 14 | Nothing Phone (2) ✍️Details: - Version: 14 - Status: #Official - Device: #Pong - Released: 07/09/2024 🔽Download :Fastboot Build | Mirror ⚙️Installation: Here 🆘Support Group :Here 🔖Tags :#Neoteric#U#CLO#ROM ✍️ Note: • Final A14 stable release. Next build will be based on A15 • This build has been tested over months and isnow ready for public usage 🏆Credits: - AOSPA team for DT - Neoteric OS Team - Testers who helped all throughout 😎Dev : @HELLBOY017 🔔Updates : @NothingPhone2Updates 🐙Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #611 · 09.05.2025 г., 10:03

Neoteric OS - CLO | Android 15 | Nothing Phone (2) ✍️Details: - Version: 15 - Device: #Pong 🔽 Download : Here | Mirror ⚙️ Installation: Here 🆘 Support Group : Here 📔 Changelogs: Here 💰 Donate: Here 🔖 Tags : #Neoteric#V#CLO#ROM#Official ✍️ Note: - Adb sideload via the linked neoteric recovery linked only! - Clean flashing is mandatory for first installation. Dirty flashing is possible for manual updation though. - OTA Updates are supported. - Latest stock firmware is recommended. - If you face Error Applying update: 7 (ErrorCode: kInstallDeviceOpenError) flash super_empty from bootloader mode using the cmd: fastboot wipe-super super_empty.img - This will serve as a standalone post for all upcoming releases for this rom. 🏆 Credits - Neoteric OS Team - Testers who helped all throughout. 👤 Dev : @HELLBOY017 🔔 Updates : @NothingPhone2Updates 🐙 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #685 · 19.10.2025 г., 19:19

Neoteric OS - CLO | Android 16 | Nothing Phone (2) [EOL] ✍️Details: - Version: 4.0 based on A16 - Device: #Pong 🔽Download : Fastboot Build ⚙️Installation: Here 🆘Support Group : Here 💰Donate: Here 🔖Tags : #Neoteric#CLO#ROM#bka 📔Changelog: - Last update - Fixed up keybox spoofing so that payzapp works ✍️Note: - Latest stock firmware is recommended. - ROM ships with Meteoric Kernel (KSUN + SUSFS) out of box. - Install cmds: fastboot update -w : for clean fastboot update : for normal - OTA Updates are supported. - If you face Error Applying update: 7 (ErrorCode: kInstallDeviceOpenError) flash super_empty from bootloader mode using the cmd: fastboot wipe-super super_empty.img 🏆Credits - Neoteric OS Team - Testers who helped all throughout. 👤Dev : @HELLBOY017 🔔Updates : @NothingPhone2Updates 🐙Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #658 · 31.07.2025 г., 15:30

Neoteric OS - CLO | Android 16 | Nothing Phone (2) ✍️Details: - Version: 4.0 based on A16 - Device: #Pong 🔽 Download : Fastboot Build | Mirror ⚙️ Installation: Here 🆘 Support Group : Here 💰 Donate: Here 🔖 Tags : #Neoteric#CLO#ROM#Official#bka (Baklava) 📔 Changelogs: - LA.QSSI.16.0.r1-07300-qssi.0 ✍️ Note: - Latest stock firmware is recommended. - ROM ships with Meteoric Kernel (KSUN + SUSFS) out of box. - For recovery based builds sideloading via the linked neoteric recovery linked only! OFOX won't work! - Install cmds: fastboot update -w : for clean fastboot update : for normal - OTA Updates are supported. - If you face Error Applying update: 7 (ErrorCode: kInstallDeviceOpenError) flash super_empty from bootloader mode using the cmd: fastboot wipe-super super_empty.img - This will serve as a standalone post for all upcoming releases for this rom. 🏆 Credits - Neoteric OS Team - Testers who helped all throughout. 👤 Dev : @AbhayGill017 🔔 Updates : @NothingPhone2Updates 🐙 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #219 · 27.12.2023 г., 07:03

Neoteric OS - CLO - Official| Android 13 | Nothing Phone (2) 📝Details: - Version: 13 - Status: #Official - Device: #Pong - Released: 27/12/22 ⬇️Download :ROM 🎙Support Group :Here 🌳Trees :DT | Kernel | Vendor 🏷Tags :#Neoteric#CAF#T#ROM ✨Changelog: • Initial release ❗️Known Issues: • NFC won't work (requires Android 14 aosp source) • SafetyNet is broken (ROM is shipped with kernelsu so u can fix it with a module) 🏆Credits: - Chandu_Dyavanapelli for initial DT Bringup - Neoteric OS Team - Testers who helped all throughout 👤Dev : @HELLBOY017 🔔Updates : @NothingPhone2Updates 🐙Chat : @NothingPhone2