Projects STRLCPY dummy Commits 953546e7
🤬
  • ■ ■ ■ ■ ■ ■
    .gitignore
     1 +# Byte-compiled / optimized / DLL files
     2 +__pycache__/
     3 +*.py[cod]
     4 +*$py.class
     5 + 
     6 +# C extensions
     7 +*.so
     8 + 
     9 +# Distribution / packaging
     10 +.Python
     11 +build/
     12 +develop-eggs/
     13 +dist/
     14 +downloads/
     15 +eggs/
     16 +.eggs/
     17 +lib/
     18 +lib64/
     19 +parts/
     20 +sdist/
     21 +var/
     22 +wheels/
     23 +share/python-wheels/
     24 +*.egg-info/
     25 +.installed.cfg
     26 +*.egg
     27 +MANIFEST
     28 + 
     29 +# PyInstaller
     30 +# Usually these files are written by a python script from a template
     31 +# before PyInstaller builds the exe, so as to inject date/other infos into it.
     32 +*.manifest
     33 +*.spec
     34 + 
     35 +# Installer logs
     36 +pip-log.txt
     37 +pip-delete-this-directory.txt
     38 + 
     39 +# Unit test / coverage reports
     40 +htmlcov/
     41 +.tox/
     42 +.nox/
     43 +.coverage
     44 +.coverage.*
     45 +.cache
     46 +nosetests.xml
     47 +coverage.xml
     48 +*.cover
     49 +*.py,cover
     50 +.hypothesis/
     51 +.pytest_cache/
     52 +cover/
     53 + 
     54 +# Translations
     55 +*.mo
     56 +*.pot
     57 + 
     58 +# Django stuff:
     59 +*.log
     60 +local_settings.py
     61 +db.sqlite3
     62 +db.sqlite3-journal
     63 + 
     64 +# Flask stuff:
     65 +instance/
     66 +.webassets-cache
     67 + 
     68 +# Scrapy stuff:
     69 +.scrapy
     70 + 
     71 +# Sphinx documentation
     72 +docs/_build/
     73 + 
     74 +# PyBuilder
     75 +.pybuilder/
     76 +target/
     77 + 
     78 +# Jupyter Notebook
     79 +.ipynb_checkpoints
     80 + 
     81 +# IPython
     82 +profile_default/
     83 +ipython_config.py
     84 + 
     85 +# pyenv
     86 +# For a library or package, you might want to ignore these files since the code is
     87 +# intended to run in multiple environments; otherwise, check them in:
     88 +# .python-version
     89 + 
     90 +# pipenv
     91 +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
     92 +# However, in case of collaboration, if having platform-specific dependencies or dependencies
     93 +# having no cross-platform support, pipenv may install dependencies that don't work, or not
     94 +# install all needed dependencies.
     95 +#Pipfile.lock
     96 + 
     97 +# poetry
     98 +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
     99 +# This is especially recommended for binary packages to ensure reproducibility, and is more
     100 +# commonly ignored for libraries.
     101 +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
     102 +#poetry.lock
     103 + 
     104 +# pdm
     105 +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
     106 +#pdm.lock
     107 +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
     108 +# in version control.
     109 +# https://pdm.fming.dev/#use-with-ide
     110 +.pdm.toml
     111 + 
     112 +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
     113 +__pypackages__/
     114 + 
     115 +# Celery stuff
     116 +celerybeat-schedule
     117 +celerybeat.pid
     118 + 
     119 +# SageMath parsed files
     120 +*.sage.py
     121 + 
     122 +# Environments
     123 +.env
     124 +.venv
     125 +env/
     126 +venv/
     127 +ENV/
     128 +env.bak/
     129 +venv.bak/
     130 + 
     131 +# Spyder project settings
     132 +.spyderproject
     133 +.spyproject
     134 + 
     135 +# Rope project settings
     136 +.ropeproject
     137 + 
     138 +# mkdocs documentation
     139 +/site
     140 + 
     141 +# mypy
     142 +.mypy_cache/
     143 +.dmypy.json
     144 +dmypy.json
     145 + 
     146 +# Pyre type checker
     147 +.pyre/
     148 + 
     149 +# pytype static type analyzer
     150 +.pytype/
     151 + 
     152 +# Cython debug symbols
     153 +cython_debug/
     154 + 
     155 +# PyCharm
     156 +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
     157 +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
     158 +# and can be added to the global gitignore or merged into this file. For a more nuclear
     159 +# option (not recommended) you can uncomment the following to ignore the entire idea folder.
     160 +#.idea/
     161 + 
     162 +*.jpeg
     163 +*.pdf
     164 +*.png
  • ■ ■ ■ ■ ■ ■
    dummy/cli.py
    skipped 3 lines
    4 4  import argparse
    5 5  import binascii
    6 6  import colorama
    7  -import pypdf
    8 7  import io
    9 8   
    10 9  from colorama import Fore, Back, Style
    11 10  from PIL import Image, ImageDraw, ImageFont
     11 +from reportlab.pdfgen import canvas
     12 +from reportlab.lib.pagesizes import B5
    12 13   
    13  -def make_png_data(text, byte_size):
    14  - image = Image.new('RGB', (516, 729), (255, 255, 255)) # B5, White
     14 +def make_png(file_path, text, byte_size):
     15 + image = Image.new('RGB', (729, 516), (255, 255, 255)) # B5, White
    15 16   draw = ImageDraw.Draw(image)
    16 17   draw.text((10, 10), text, fill=(0, 0, 0)) # Black
    17 18   output = io.BytesIO()
    skipped 1 lines
    19 20   png_data = output.getvalue()
    20 21   
    21 22   if len(png_data) > byte_size:
    22  - with open('dummy.png', 'wb') as f:
     23 + with open(file_path, 'wb') as f:
    23 24   f.write(png_data)
    24  - return None
     25 + return False
    25 26   
    26 27   # IEND chunk is the last chunk of a PNG file
    27 28   iend_type_index = png_data.find(b'IEND')
    28 29   if iend_type_index == -1:
    29 30   print(Fore.RED + 'Error: IEND chunk not found.')
    30  - return None
     31 + return False
    31 32   
    32 33   # The first 4 bytes of the IEND chunk are data length
    33 34   # IEND chunk type (4 bytes) follows IEND chunk data length (4 bytes)
    skipped 2 lines
    36 37   # 12 = 4 (chunk length) + 4 (chunk type) + 4 (chunk CRC)
    37 38   extra_chunk_length = byte_size - len(png_data) - 12
    38 39   # private chunk type
    39  - extra_chunk_type = b'exTr'
     40 + extra_chunk_type = b'eXtr'
    40 41   extra_chunk_data = b'\x00' * extra_chunk_length
    41 42   extra_chunk_crc = binascii.crc32(extra_chunk_type + extra_chunk_data)
    42 43   extra_chunk = extra_chunk_length.to_bytes(4, byteorder='big')
    skipped 1 lines
    44 45   extra_chunk += extra_chunk_crc.to_bytes(4, byteorder='big')
    45 46   
    46 47   added_png_data = png_data[:iend_chunk_index] + extra_chunk + png_data[iend_chunk_index:]
    47  - return added_png_data
     48 + with open(file_path, 'wb') as f:
     49 + f.write(added_png_data)
     50 + return True
     51 + 
     52 +def make_pdf(file_path, text):
     53 + c = canvas.Canvas(file_path, bottomup=False, pagesize=B5)
     54 + c.setFont('Helvetica', 30)
     55 + c.drawString(15, 40, text)
     56 + c.showPage()
     57 + c.save()
    48 58   
    49 59  def parse_args():
    50 60   colorama.init(autoreset=True)
    51 61   parser = argparse.ArgumentParser(description='Create a dummy file of the specified size.')
    52  - parser.add_argument('-type', '--type', help='File type', choices=['png', 'pdf', 'txt'], required=True)
    53  - parser.add_argument('-text', '--text', help='Text to be written in the file')
    54  - parser.add_argument('-size', '--size', help='File size (bytes)', type=int)
     62 + parser.add_argument('-n', '--name', help='File name(.png, .pdf)', required=True)
     63 + parser.add_argument('-t', '--text', help='Text to be written in the file')
     64 + parser.add_argument('-s', '--size', help='Bytes of file(png only)', type=int)
    55 65   args = parser.parse_args()
    56  - if args.type == 'png':
    57  - added_png_data = make_png_data(args.text, args.size)
    58  - with open('dummy.png', 'wb') as f:
    59  - f.write(added_png_data)
    60  - else:
    61  - print(Fore.RED + 'Error: Invalid file type.')
    62  - parser.print_help()
     66 + # if args.name.endswith('.png'):
    63 67   
    64 68  if __name__ == '__main__':
    65 69   colorama.init(autoreset=True)
    66  - png_data = make_png_data('sample png', 400001)
    67  - with open('dummy.png', 'wb') as f:
    68  - f.write(png_data)
     70 + make_pdf('dummy.pdf', 'sample pdf')
    69 71   
Please wait...
Page is in error, reload to recover