1. Python / Говнокод #27980

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    def res_horizontal(self, btn):
            self.im = Image.open(self.new_img)
            if btn.text() == "320x240":
                self.new_im = self.im.resize((320, 240))
            elif btn.text() == '1024x600':
                self.new_im = self.im.resize((1024, 600))
            elif btn.text() == '1280x720':
                self.new_im = self.im.resize((1280, 720))
            elif btn.text() == '1440x900':
                self.new_im = self.im.resize((1440, 900))
            elif btn.text() == '1600x1024':
                self.new_im = self.im.resize((1600, 1024))
            elif btn.text() == '1920x1080':
                self.new_im = self.im.resize((1920, 1080))
            elif btn.text() == '2048x1536':
                self.new_im = self.im.resize((2048, 1536))
            elif btn.text() == '2560x1440':
                self.new_im = self.im.resize((2560, 440))
            elif btn.text() == '3840x2160':
                self.new_im = self.im.resize((3840, 2160))
            elif btn.text() == '4096x2160':
                self.new_im = self.im.resize((4096, 2160))
            elif btn.text == '800x480':
                self.new_im = self.im.resize((800, 480))
    
            self.new_im.save(self.new_img)
    
        def res_vertical(self, btn):
            self.im = Image.open(self.new_img)
            if btn.text() == '240x320':
                self.new_im = self.im.resize((240, 320))
            elif btn.text() == '480x800':
                self.new_im = self.im.resize((480, 800))
            elif btn.text() == '600x1024':
                self.new_im = self.im.resize((600, 1024))
            elif btn.text() == '720x1280':
                self.new_im = self.im.resize((720, 1280))
            elif btn.text() == '900x1440':
                self.new_im = self.im.resize((900, 1440))
            elif btn.text() == '1024x1600':
                self.new_im = self.im.resize((1024, 1600))
            elif btn.text() == '1080x1920':
                self.new_im = self.im.resize((1080, 1920))
            elif btn.text() == '1536x2048':
                self.new_im = self.im.resize((1536, 2048))
            elif btn.text() == '1440x2560':
                self.new_im = self.im.resize((1440, 2560))
            elif btn.text() == '2160x3840':
                self.new_im = self.im.resize((2160, 3840))
            elif btn.text() == '2160x4096':
                self.new_im = self.im.resize((2160, 4096))
    
            self.new_im.save(self.new_img)
    
        def res_square(self, btn):
            self.im = Image.open(self.new_img)
            if btn.text() == '320x320':
                self.new_im = self.im.resize((320, 320))
            elif btn.text() == '800x800':
                self.new_im = self.im.resize((800, 800))
            elif btn.text() == '1280x1280':
                self.new_im = self.im.resize((1280, 1280))
            elif btn.text() == '1024x1024':
                self.new_im = self.im.resize((1024, 1024))
            elif btn.text() == '1600x1600':
                self.new_im = self.im.resize((1600, 1600))
            elif btn.text() == '1440x1440':
                self.new_im = self.im.resize((1440, 1440))
            elif btn.text() == '1920x1920':
                self.new_im = self.im.resize((1920, 1920))
            elif btn.text() == '2048x2048':
                self.new_im = self.im.resize((2048, 2048))
            elif btn.text() == '3840x3840':
                self.new_im = self.im.resize((3840, 3840))
            elif btn.text() == '2560x2560':
                self.new_im = self.im.resize((2560, 2560))
            elif btn.text() == '4096x4096':
                self.new_im = self.im.resize((4096, 4096))
    
            self.new_im.save(self.new_img)

    Давным давно на pyqt писал этот говнокод, теперь ржу над ним

    ponos334, 31 Января 2022

    Комментарии (70)
  2. Python / Говнокод #27971

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    #!/usr/bin/env python3
    
    import subprocess as sp
    
    lines_pipe = sp.Popen(('xinput', 'list'), stdout=sp.PIPE)
    id_line = str(sp.check_output(('grep', 'Touchpad'), stdin=lines_pipe.stdout))
    
    a = id_line.index("id=") + 3
    b = a
    
    while id_line[b] in set(list("0123456789")):
        b += 1
    
    id = id_line[a:b]
    
    status_pipe = sp.Popen(('xinput', 'list-props', id), stdout=sp.PIPE)
    sp.run(('xinput', ['enable', 'disable'][int(str(sp.check_output(('grep', 'Device Enabled'), stdin=status_pipe.stdout))[-4]=='1')], id))

    Предыдущий прыщескрипт на bash соснул, так как захардкоженный "id", оказалось, иногда может меняться, поэтому скрипт был благополучно перенесён на "Python".

    JloJle4Ka, 27 Января 2022

    Комментарии (104)
  3. Python / Говнокод #27963

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    def number_to_words(n):
        if n == 1:
            print('один')
            exit()
        elif n == 2:
            print('два')
            exit()
        elif n == 3:
            print('три')
            exit()
        elif n == 4:
            print('четыре')
            exit()
        elif n == 5:
            print('пять')
            exit()
        elif n == 6:
            print('шесть')
            exit()
        elif n == 7:
            print('семь')
            exit()
        elif n == 8:
            print('восемь')
            exit()
        elif n == 9:
            print('девять')
            exit()
        elif n == 10:
            print('десять')  
            exit()
        elif n == 11:
            print('одиннадцать')
            exit()
        elif n == 12:
            print('двенадцать')
            exit()
        elif n == 13:
            print('тринадцать')
            exit()
        elif n == 14:
            print('четырнадцать')
            exit()
        elif n == 15:
            print('пятнадцать')
            exit()
        elif n == 16:
            print('шестнадцать')
            exit()
        elif n == 17:
            print('семнадцать')
            exit()
        elif n == 18:
            print('восемнадцать')
            exit()
        elif n == 19:
            print('девятнадцать')
            exit()
        elif n == 20:
            print('двадцать')
            exit()
        elif n == 21:
            print('двадцать один')
            exit()
        elif n == 22:
            print('двадцать два')
            exit()
        elif n == 23:
            print('двадцать три')
            exit()
        elif n == 24:
            print('двадцать четыре')
            exit()
        elif n == 25:
            print('двадцать пять')
            exit()
        elif n == 26:
            print('двадцать шесть')
            exit()
        elif n == 27:
            print('двадцать семь')
            exit()
        elif n == 28:
            print('двадцать восемь')  
            exit()
        elif n == 29:
            print('двадцать девять')
            exit()
        elif n == 30:
            print('тридцать')
            exit()
        elif n == 31:
            print('тридцать один')
            exit()
        elif n == 32:
            print('тридцать два')
            exit()

    так до 99. Оригинал: https://www.cyberforum.ru/python-beginners/thread2390750.html
    P.S. exit-ы то зачем????

    makpif, 21 Января 2022

    Комментарии (49)
  4. Python / Говнокод #27953

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    a = int(input('Введите число A: '))
    b = int(input('Введите число B: '))
    c = int(input('Введите число C: '))
    d = int(input('Введите число D: '))
    
    if a % 2 == 0 and  b % 2 == 0 and c % 2 == 0 and d % 2 == 0:
    	print ('Все числа четные')
    elif a % 2 != 0 and  b % 2 == 0 and c % 2 == 0 and d % 2 == 0:
    	print ('Все числа четные, кроме числа А')
    elif a % 2 == 0 and  b % 2 != 0 and c % 2 == 0 and d % 2 == 0:
    	print ('Все числа четные, кроме числа B')
    elif a % 2 == 0 and  b % 2 == 0 and c % 2 != 0 and d % 2 == 0:
    	print ('Все числа четные, кроме числа C')
    elif a % 2 == 0 and  b % 2 == 0 and c % 2 == 0 and d % 2 != 0:
    	print ('Все числа четные, кроме числа D')
    
    elif a % 2 != 0 and  b % 2 != 0 and c % 2 == 0 and d % 2 == 0:
    	print ('Числа C и D четные, а А и B нет')
    elif a % 2 != 0 and  b % 2 == 0 and c % 2 != 0 and d % 2 == 0:
    	print ('Числа B и D четные, а А и C нет')
    elif a % 2 != 0 and  b % 2 == 0 and c % 2 == 0 and d % 2 != 0:
    	print ('Числа B и C четные, а А и D нет')
    # with B
    elif a % 2 == 0 and  b % 2 != 0 and c % 2 != 0 and d % 2 == 0:
    	print ('Числа A и D четные, а B и C нет')
    elif a % 2 != 0 and  b % 2 == 0 and c % 2 != 0 and d % 2 == 0:
    	print ('Числа B и D четные, а А и C нет')
    elif a % 2 != 0 and  b % 2 == 0 and c % 2 == 0 and d % 2 != 0:
    	print ('Числа B и C четные, а А и D нет')
    
    elif a % 2 == 0 and  b % 2 == 0 and c % 2 != 0 and d % 2 != 0:
    	print ('Числа A и B четные, а C и D нет')
    
    elif a % 2 == 0 and  b % 2 != 0 and c % 2 != 0 and d % 2 != 0:
    	print ('Все числа нечетные, кроме числа А')
    elif a % 2 != 0 and  b % 2 == 0 and c % 2 != 0 and d % 2 != 0:
    	print ('Все числа нечетные, кроме числа B')
    elif a % 2 != 0 and  b % 2 != 0 and c % 2 == 0 and d % 2 != 0:
    	print ('Все числа нечетные, кроме числа C')
    elif a % 2 != 0 and  b % 2 != 0 and c % 2 != 0 and d % 2 == 0:
    	print ('Все числа нечетные, кроме числа D')
    else:
    	print ('Введите только целые числа')

    lainde, 14 Января 2022

    Комментарии (33)
  5. Python / Говнокод #27947

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    def foo(n):
        f = True
        k = n % 10
        while n > k:
            n //= 10
            if n % 10 != k:
                f = False
                break
        return f
    
    array = [
        [22, 14, 8, 14],
        [22, 13, 70, 95],
        [22, 12, 51, 10], # Для тестирования
        [20, 11, 51, 56],
        [49, 10, 36, 85]
    ]
    
    f2 = True
    for i in range(len(array[0])):
        c = 0
        for j in range(len(array)):
            if foo(array[j][i]):
                c += 1
        if c > 3:
            f2 = False
            break
    print("True" if f2 else "False")

    Lisya, 12 Января 2022

    Комментарии (38)
  6. Python / Говнокод #27912

    +1

    1. 1
    description = f"""У тебя , **{ctx.author}** вот столько балов!**{cursor.execute("SELECT cash FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[0]} :polegar_para_cima:**"""

    Насмотревшиеся Хауди Хо ботопейсатели - это, конечно, нечто.
    1. Выполнение SQL-запроса вставлено прямо в шаблонизируемую строку
    2. Сам запрос формируется через форматирование строки (привет, Бобби Тейблз!)
    3. Не проверяется, вернула ли база хоть что-то.

    "Не могу понять в чем проблема?" (с)

    Vindicar, 02 Января 2022

    Комментарии (48)
  7. Python / Говнокод #27866

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    #!/usr/bin/python
      
      import sys
      
      cache = {}
      
      def count(start, end):
          if start < end:
              if start not in cache:
                  cache[start] = count(start + 1, end) + count(start * 2, end) + count(start ** 2, end)
              return cache[start]
          elif start == end:
              return 1
          else:
              return 0
    
      print(count(int(sys.argv[1]), int(sys.argv[2])))

    Подсчитать количество путей из a в b с помощью прибавления единицы, умножения на 2 и возведения в квадрат

    Чем формально ограничены возможности преобразовать рекурсию в хвостовую? Вот такое ведь не преобразовать?

    vistefan, 11 Декабря 2021

    Комментарии (23)
  8. Python / Говнокод #27865

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    def export_to_csv(model, fields=None, related_models=[]):
        def export(request):
            meta = model._meta
            queryset = model.objects.all()
            
            if fields is not None:
                field_names = fields
            elif 'Shops' in related_models and 'Spots' in related_models:
                field_names = [field.name for field in Shops._meta.fields] +\
                    [field.name for field in Spots._meta.fields]
            elif 'Products' in related_models and 'Spots' in related_models:
                field_names = [field.name for field in Products._meta.fields] +\
                    [field.name for field in Spots._meta.fields]
            else:
                field_names = []
                for field in meta.fields:
                    if not field.name in FORBIDDEN_FIELDS:
                        field_names.append(field.name)
    
            response = HttpResponse(content_type='text/csv')
            response['Content-Disposition'] = 'attachment; filename={}.csv'.format(meta)
            response.write(u'\ufeff'.encode('utf8'))
    
            writer = csv.writer(response, delimiter=',', lineterminator='\n', quoting=csv.QUOTE_ALL, dialect='excel')
            writer.writerow(field_names)
    
            if len(related_models) == 0:
                for obj in queryset:
                    row = writer.writerow([getattr(obj, field) for field in field_names])
    
            elif 'Shops' in related_models and 'Spots' in related_models:
                shops_fields = [field.name for field in Shops._meta.fields]
                contact_fields = [field.name for field in Spots._meta.fields]
    
                for obj in queryset:
                    row = []
    
                    if obj.Shops is not None:
                        row += [getattr(obj.Shops, field) for field in shops_fields]
                    else:
                        row += ['' for field in shops_fields]
    
                    if obj.Contact is not None:
                        row += [getattr(obj.Contact, field) for field in contact_fields]
                    else:
                        row += ['' for field in contact_fields]
    
                    writer.writerow(row)
                
            elif 'Products' in related_models and 'Spots' in related_models:
                products_fields = [field.name for field in Products._meta.fields]
                contact_fields = [field.name for field in Spots._meta.fields]
                
                for obj in queryset:
                    row = []
                    
                    if obj.Products is not None:
                        row += [getattr(obj.Products, field) for field in products_fields]
                    else:
                        row += ['' for field in products_fields]
    
                    if obj.Contact is not None:
                        row += [getattr(obj.Contact, field) for field in contact_fields]
                    else:
                        row += ['' for field in contact_fields]
                    
                    writer.writerow(row)
    
            return response
    
        return export

    В юности нагородила вот такую портянку для экспорта в csv связных между собой таблиц. Связка данных на уровне DAO-шки (в терминологии Джанго - Managers)? Пфф... Только инжект if-else с копипастой связки данных, только хардкор!

    JaneBurt, 11 Декабря 2021

    Комментарии (331)
  9. Python / Говнокод #27756

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    class UserCreate(MethodView):
        """Data create."""
    
        def post(self):
            """Создание данных."""
            q = 1
            values = {}
            values['person'] = request.json_schema["person"]
            values['date_opr'] = request.json_schema["dateOpr"]
            values['year_input'] = request.json_schema["yearInput"]
            values['vuz'] = request.json_schema["vuz"]
            values['person_id'] = request.json_schema["personId"]
            q = 1
            with session_scope() as session:
                id = candidate_service.create_item(session, values)
            return {"msg": "Данные созданы", "data": {"id": id}}

    зачем эта переменная q???

    super_govnokoder, 18 Октября 2021

    Комментарии (36)
  10. Python / Говнокод #27617

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    # Дамп базы хуза
    # Постобработка export-а из MySQL
    
    import pandas as pd
    import numpy as np
    import csv
    
    comments = pd.read_csv('/wp_comments-2.csv', header=None)
    comments.head()
    
    ##
    
    comments_clean = pd.DataFrame({
        'comment_id': comments[0],
        'comment_post_id': comments[1],
        'comment_parent': comments[13],
        'name': comments[2],
        'gravatar_hash': comments[3].str.split('@').str[0],
        'gravatar_domain': comments[3].str.split('@').str[1],
        'profile': comments[4],
        'date': comments[6],
        'content': comments[8],
    })
    
    ##
    
    comments_clean[(comments_clean.gravatar_domain != 'lo.ol') & ~comments_clean.gravatar_domain.isna()]
    
    ##
    
    comments_clean = comments_clean[(comments_clean.gravatar_domain == 'lo.ol') | comments_clean.gravatar_domain.isna()]
    comments_clean.drop(columns=['gravatar_domain'], inplace=True)
    comments_clean.head()
    
    ##
    
    posts = pd.read_csv('/wp_posts.csv', header=None)
    posts = posts[(posts[20] == 'post') & (posts[7] == 'publish') & (posts[11].str.match('^_'))]
    posts.head()
    
    ##
    
    posts_clean = pd.DataFrame({
        'post_id': posts[0],
        'date': posts[2],
        'content': posts[4],
        'description': posts[6],
        'original_id': posts[11].str[1:]
    })
    posts_clean.head()
    
    ##
    
    comments_clean.to_csv('~/Downloads/gost/comments.csv', index=False)
    posts_clean.to_csv('~/Downloads/gost/posts.csv', index=False)

    https://govnokod.xyz/dump/wp_gk_legacy_users.csv
    ../comments.csv
    ../posts.csv

    guest6, 26 Августа 2021

    Комментарии (25)