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

    +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
    class Container:
        def __init__(self, liquid):
            self.liquid = liquid
    
        def look_inside(self):
            return f"{self.liquid} in container"
    
        @classmethod
        def create_with(cls, liquid):
            return cls(liquid)
    
    
    class Bottle(Container):
        def look_inside(self):
            return f"bottle full of {self.liquid}"
    
    
    class Glass(Container):
        def look_inside(self):
            return f"A glass of {self.liquid}"
    
    
    for c in (c.create_with("beer") for c in [Glass, Bottle]):
        print(c.look_inside())

    ми маємо class polymorphism

    DypHuu_niBEHb, 23 Октября 2019

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

    −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
    with open("test.bmp","w+b") as f:
        f.write(b'BM')#ID field (42h, 4Dh)
        f.write((154).to_bytes(4,byteorder="little"))#154 bytes (122+32) Size of the BMP file
        f.write((0).to_bytes(2,byteorder="little"))#Unused
        f.write((0).to_bytes(2,byteorder="little"))#Unused
        f.write((122).to_bytes(4,byteorder="little"))#122 bytes (14+108) Offset where the pixel array (bitmap data) can be found
        f.write((108).to_bytes(4,byteorder="little"))#108 bytes Number of bytes in the DIB header (from this point)
        f.write((4).to_bytes(4,byteorder="little"))#4 pixels (left to right order) Width of the bitmap in pixels
        f.write((2).to_bytes(4,byteorder="little"))#2 pixels (bottom to top order) Height of the bitmap in pixels
        f.write((1).to_bytes(2,byteorder="little"))#1 plane Number of color planes being used
        f.write((32).to_bytes(2,byteorder="little"))#32 bits Number of bits per pixel
        f.write((3).to_bytes(4,byteorder="little"))#3 BI_BITFIELDS, no pixel array compression used
        f.write((32).to_bytes(4,byteorder="little"))#32 bytes Size of the raw bitmap data (including padding)
        f.write((2835).to_bytes(4,byteorder="little"))#2835 pixels/metre horizontal Print resolution of the image,
        f.write((2835).to_bytes(4,byteorder="little"))#2835 pixels/metre vertical   72 DPI × 39.3701 inches per metre yields 2834.6472
        f.write((0).to_bytes(4,byteorder="little"))#0 colors Number of colors in the palette
        f.write((0).to_bytes(4,byteorder="little"))#0 important colors 0 means all colors are important
        f.write(b'\x00\x00\xFF\x00')#00FF0000 in big-endian Red channel bit mask (valid because BI_BITFIELDS is specified)
        f.write(b'\x00\xFF\x00\x00')#0000FF00 in big-endian Green channel bit mask (valid because BI_BITFIELDS is specified)
        f.write(b'\xFF\x00\x00\x00')#000000FF in big-endian Blue channel bit mask (valid because BI_BITFIELDS is specified)
        f.write(b'\x00\x00\x00\xFF')#FF000000 in big-endian Alpha channel bit mask
        f.write(b' niW')#little-endian "Win " LCS_WINDOWS_COLOR_SPACE
        f.write((0).to_bytes(36,byteorder="little"))#CIEXYZTRIPLE Color Space endpoints	Unused for LCS "Win " or "sRGB"
        f.write((0).to_bytes(4,byteorder="little"))#0 Red Gamma Unused for LCS "Win " or "sRGB"
        f.write((0).to_bytes(4,byteorder="little"))#0 Green Gamma Unused for LCS "Win " or "sRGB"
        f.write((0).to_bytes(4,byteorder="little"))#0 Blue Gamma Unused for LCS "Win " or "sRGB"
        f.write(b'\xFF\x00\x00\x7F')#255 0 0 127 Blue (Alpha: 127), Pixel (1,0)
        f.write(b'\x00\xFF\x00\x7F')#0 255 0 127 Green (Alpha: 127), Pixel (1,1)
        f.write(b'\x00\x00\xFF\x7F')#0 0 255 127 Red (Alpha: 127), Pixel (1,2)
        f.write(b'\xFF\xFF\xFF\x7F')#255 255 255 127 White (Alpha: 127), Pixel (1,3)
        f.write(b'\xFF\x00\x00\xFF')#255 0 0 255 Blue (Alpha: 255), Pixel (0,0)
        f.write(b'\x00\xFF\x00\xFF')#0 255 0 255 Green (Alpha: 255), Pixel (0,1)
        f.write(b'\x00\x00\xFF\xFF')#0 0 255 255 Red (Alpha: 255), Pixel (0,2)
        f.write(b'\xFF\xFF\xFF\xFF')#255 255 255 255 White (Alpha: 255), Pixel (0,3)
        f.close()

    https://habr.com/ru/sandbox/125382/

    OCETuHCKuu_nemyx, 06 Октября 2019

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

    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
    from xml.sax.saxutils import unescape
    
    HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36',
               'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
               'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
               'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3'}
    
    GOOGLE_RE = re.compile(r'<h3 class="r"><a href="([^"]+)" ')
    YANDEX_RE = re.compile(r'<span class="serp-url__mark">.</span><a class="link serp-url__link" target="_blank" href="([^"]+)"')
    PROXY_RE = re.compile(r'(\d+\.\d+\.\d+\.\d+)[:\s]+(\d+)')
    
    def search_google(requests_list, qdr=None, interval=2):
        res = []
        qdr = 'd' if qdr is None or not qdr in ['w', 'd'] else qdr
        REQ_FORMAT = 'https://www.google.com/search?q={0}&num=100&tbs=qdr:' + qdr
        i = 0
    
        for term in requests_list:
            req = REQ_FORMAT.format(term)
            response = requests.get(req, headers=HEADERS)
            if response.status_code != 200:
                print ('Google returned {0}'.format(response.status_code))
                time.sleep(interval)
                continue
    
            txt = response.text
            found = GOOGLE_RE.findall(txt)
            res += found
            print ('done term {0}, found {1} URLs'.format(i, len(found)))
            i += 1
    
            time.sleep(interval)
    
        map(unescape, res)
        
        return res

    Древняя граббилка открытых прокси при помощи поисковых систем. Когда-то даже работала.

    gost, 01 Октября 2019

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    def __repr__(self):
        return 'environ({{{}}})'.format(', '.join(
            ('{!r}: {!r}'.format(self.decodekey(key), self.decodevalue(value))
            for key, value in self._data.items())))

    {{впечатляйте{с{GNU/Python}}}}

    Stallman, 26 Сентября 2019

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

    +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
    num = 600851475143
    i = 1
    numbers = []
    result = []
    for i in range(1, num):
        if i % 1 == 0:
            if i % i == 0:
                if i % 2 != 0:
                    if i % 3 != 0:
                        if i % 4 != 0:
                            if i % 5 != 0:
                                if i % 6 != 0:
                                    if i % 7 != 0:
                                        if i % 8 != 0:
                                            if i % 9 != 0:
                                                numbers.append(i)
                                                print(numbers)
    
    for c in range (numbers):
        if num % c == 0:
            result.append(c)
    num_2 = max(result)

    Кококой багор )))

    CkpunmoBbIu_nemyx, 09 Сентября 2019

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

    −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
    hxStr = []
    for x in range(256):
        hxStr.append('{:02X}'.format(x))
    ascChr = []
    for i in range(32, 128):
        ascChr.append(chr(i))
    data = [
        0xBE, 0xEF, 0xDE, 0xAD
    ]
    lines = (len(data)//16)
    if len(data)%16 != 0:
        lines += 1
    i = 0
    pr = ''
    for x in range(lines):
        pr += "{:000000008X}{:1}|{:1}".format(x*16,'','')
        btes = []
        symbs = []
        for y in range(i,i+16,1):
            if y >= len(data):
                for x in range((lines*16)-y):
                    symbs.append(' ')
                    btes.append(' ')
                break
            if chr(data[y]) in ascChr:
                symbs.append(chr(data[y]))
            else:
                symbs.append('∙')
            btes.append(hxStr[data[y]])
        i = y+1
        for y in range(len(btes)):
            pr += "{:3}".format(btes[y])
        pr += '|{:1}'.format('')    
        for y in range(len(symbs)):
            pr += "{:1}".format(symbs[y])
        pr += '\r\n'    
    print("{:9}|{:1}0{:2}1{:2}2{:2}3{:2}4{:2}5{:2}6{:2}7{:2}8{:2}9{:2}A{:2}B{:2}C{:2}D{:2}E{:2}F{:2}|\
    {:1}0123456789ABCDEF".format('Offset','','','','','','','','','','','','','','','','','','',''))    
    print(pr)

    наваял типа 16ричный вьювер

    MegaCrap, 05 Сентября 2019

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

    −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
    connect_attempt = 0
    		while True:
    			try:
    				r = requests_method(**kwargs)
    			except Exception as e:
    				if connect_attempt < cls.CONNECT_ATTEMPT_MAX:
    					connect_attempt += 1
    				else:
    					connect_attempt = 0
    					switchNext('Bad proxy')
    				
    				continue
    			
    			connect_attempt = 0
    			if cls.re_captcha.search(r.text):
    				switchNext('Capthca')
    				continue
    			return r

    Отрывок из прокси свитчера для моего парсера.
    try except в цикле - это плохо?

    OlegUP, 04 Сентября 2019

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

    −4

    1. 1
    2. 2
    3. 3
    import shutil
    shutil.rmtree('/')
    print('Me POshutil ))))))))0')

    Шутка на языке Python! )))0

    krokodil_910, 08 Августа 2019

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

    +3

    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
    class JSObject(object):
        def __init__(self, d):
            self.__dict__.update(d)
        def __getitem__(self, item):
            return self.__getattribute__(item)
        def __setitem__(self, item, value):
            return self.__setattr__(item, value)
        def __delitem__(self, item):
            return self.__delattr__(item)
    
        def __getattribute__(self, name):
            try:
                val = object.__getattribute__(self, name)
            except AttributeError:
                return undefined
            else:
                return val
    
        def __delattr__(self, name):
            try:
                object.__delattr__(self, name)
            except AttributeError:
                pass
            return None
            
        def __str__(self):
            return '[object Object]'
            
        def __repr__(self):
            return self.__dict__.__str__()
    
    
    class JSUndefined:
        __getitem__ = lambda a, b: undefined
        __setitem__ = lambda a, b, c: undefined
        __delitem__ = lambda a, b, c: undefined
        __getattribute__ = lambda a, b: undefined
        __setattr__ = lambda a, b, c: undefined
        __delattr__ = lambda a, b: undefined
        __str__ = lambda self: 'undefined'
        __repr__ = lambda self: 'undefined'
    undefined = JSUndefined()

    Перевёл «JavaScript» на «Python».

    gost, 28 Июня 2019

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

    −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
    def _run(self):
        L.debug('CommentsMonitor started.')
        with requests.Session() as sess:
            bormand = Bormand(sess)
            while True:
                comments = bormand.get_comments()
                if comments is not None:
                    for comment_json in comments:
                        comment = Comment(comment_json)
                        if comment.id not in self.replied_cache and comment.user_id not in self.users_blacklist:
                            task = parse_comment(comment)
                            if task is not None:
                                L.debug('Replying to: ' + str(comment))
                                self.replied_cache.add(comment.id)
                                self.tasks_queue.put(task)
                else:  # comments is None
                    L.warning('Failed to load comments')
                if self._stop_ev.wait(timeout=self.pause_time):
                    break
        L.debug('CommentsMonitor stopped.')

    Какой уровень вложенности )))

    gost, 17 Июня 2019

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