Skip to content

Instantly share code, notes, and snippets.

@ksur
Created October 30, 2023 14:08
Show Gist options
  • Save ksur/3c992403c05d3c6806fe0edd7f17986e to your computer and use it in GitHub Desktop.
Save ksur/3c992403c05d3c6806fe0edd7f17986e to your computer and use it in GitHub Desktop.
faker_polskie_numery_telefonow.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyOirqACiETKjx6omvsWtEqb",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/ksur/3c992403c05d3c6806fe0edd7f17986e/faker_polskie_numery_telefonow.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# Generowanie danych testowych\n",
"#### Skrypt generuje \"polskie\" numery telefonów komórkowych. W tym celu wykorzystuje bibliotekę Faker."
],
"metadata": {
"id": "3kUhQkiY5OXn"
}
},
{
"cell_type": "markdown",
"source": [
"#### Instalacja biblioteki Faker\n",
"Biblioteka nie jest domyślnie dostępna w środowisku Google Colab."
],
"metadata": {
"id": "QvHjHnk55c4s"
}
},
{
"cell_type": "code",
"source": [
"!pip install faker"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wKmZaRH8O4If",
"outputId": "90680bdc-0018-4516-ef5c-fe6cb32cb4bc"
},
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Collecting faker\n",
" Downloading Faker-19.12.0-py3-none-any.whl (1.7 MB)\n",
"\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/1.7 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.1/1.7 MB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m25.6 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m20.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: python-dateutil>=2.4 in /usr/local/lib/python3.10/dist-packages (from faker) (2.8.2)\n",
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.4->faker) (1.16.0)\n",
"Installing collected packages: faker\n",
"Successfully installed faker-19.12.0\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"#### Kod skryptu"
],
"metadata": {
"id": "htlibQv_5ZIX"
}
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "2ZmNZrCJOutO",
"outputId": "63518086-25f2-420f-db3f-97d7e871ff8e"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"+48 586639271\n",
"+48 728427654\n",
"+48 746647711\n",
"+48 812735475\n",
"+48 666982303\n"
]
}
],
"source": [
"# import faker lib\n",
"from faker import Faker\n",
"\n",
"# let's define the function which return the mobile phone\n",
"def generate_polish_mobile_number(fake):\n",
" first_digit = random.choice([5, 6, 7, 8])\n",
" remaining_digits = [random.randint(0, 9) for _ in range(8)]\n",
" mobile_number = f\"+48 {first_digit}{''.join(map(str, remaining_digits))}\"\n",
" return mobile_number\n",
"\n",
"# set-up for PL locale\n",
"fake = Faker(['pl_PL'])\n",
"\n",
"# Import the random module\n",
"import random\n",
"\n",
"# generate 5 Polish mobile numbers\n",
"# result is printend \"on the screen\"\n",
"for _ in range(5):\n",
" print(generate_polish_mobile_number(fake))\n"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment