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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    try:
            assert isinstance(tag, bs4.element.Tag)
        except AssertionError:
            raise TypeError

    syoma, 20 Мая 2018

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

    −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
    import json
    import time
    import requests
    from multiprocessing.dummy import Pool as ThreadPool
    max_threads = 10
    fname = "data.json"
    headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36", "referer":"https://datmusic.xyz/?q=Home+resonance", "authority":"api-2.datmusic.xyz"}
    
    def api(url):
        while True:
            try:
                r = requests.get(url, headers=headers)
                r = r.json()
                if r['status'] == 'error':
                    pass
                else:
                    return r['data'][0]['download']
            except Exception as e:
                pass
    def download(a):
        # open in binary mode
        while True:
            try:
                with open(a[1]+".mp3", "wb") as file:
                    response = requests.get(a[0],headers=headers)
                    if not (response.status_code == 503):
                        file.write(response.content)
                        print(a[1],"downloaded")
                        break
                    else:
                        pass
            except Exception as e:
                pass
    
    songs = []
    
    with open(fname) as json_data:
        data = json.load(json_data)
        for mp3 in data['list']:
            song = []
            autor = mp3[4]
            title = mp3[3][:-5]
            song.append(autor)
            song.append(title)
            songs.append(song)
    
    links = []
    
    def linker(a):
        song = []
        link = api("https://api-2.datmusic.xyz/search?q=" + a[0] + "+" + a[1] + "&page=0")
        song.append(link)
        song.append(a[0] + ' - ' + a[1])
        links.append(song)
        print(a[1])
    
    for a in songs:
        linker(a)
        #if len(links) > 10:
        #   break
    
    pool = ThreadPool(max_threads)
    results = pool.map(download, links)
    pool.close()
    pool.join()

    #Наговнокодил загрущик плейлистов с контача. Как получить json плейлиста подумай сам (перейди в музыку, открой Network в f12 и мониторь запрос при открытии плейлиста)
    #Парсер 1 поточный, загрущик многопоточный. Работает через апи datmusic.xyz спс им
    #vk.com music downloader v1.0a
    #загрущик музыки вк
    json = https://gist.githubusercontent.com/alekxeyuk/a1ccd2c62ab56a71320a02582cfc06f9/raw/4f2622c4beeddfa7e3082c276e1c138c87478e83/data.json

    pacaw, 17 Мая 2018

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

    −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
    secs = 0
    fsecs = 0.0
    mins = 40
    lastsecs = 0
    prevsecs = 0
    
    def getTimeStr() :
        def f ( x ) :
            if ( 10 <= x <= 19 ) : return ''
            y = x % 10
            if ( y == 1 ) : return 'а'
            if ( 2 <= y <= 4 ) : return 'ы'
            return ''
        return 'Время: %d минут%s %d секунд%s' % ( mins , f ( mins ) , secs , f ( secs ) )
    
    def updateTimer() :
        global timeString , root , secs , fsecs , lastsecs , prevsecs , mins
        if ( fin ) : return
        prevsecs , lastsecs = lastsecs , clock()
        t = secs
        if ( fsecs > 0 ) :
            fsecs -= lastsecs - prevsecs
            secs = int ( fsecs )
        elif ( mins > 0 ) :
            mins -= 1
            fsecs = 60 + fsecs - lastsecs + prevsecs
            secs = int ( fsecs )
        else :
            finish()
        if ( secs == t ) :
            timeString [ 'text' ] = getTimeStr()
        root.after ( 100 , updateTimer )

    Святая Питония и tkinter

    shit_again, 12 Мая 2018

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

    −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
    from itertools import *
    
    lines = tuple ( chain ( ( tuple ( product ( *g ( range ( 3 ) , ( i , ) ) ) ) for g in ( lambda i , j : ( i , j ) , lambda i , j : ( j , i ) ) for i in range ( 3 ) ) , ( ( ( 0 , 0 ) , ( 1 , 1 ) , ( 2 , 2 ) ) , ( ( 2 , 0 ) , ( 1 , 1 ) , ( 0 , 2 ) ) ) ) )
    
    def aimove ( table , i , j ) :
        from random import choice
        possiblewin = ( lambda x : ( lambda f : ( lambda x : len ( x ) and x [ 0 ] ) ( tuple ( filter ( lambda x : x , map ( f , lines ) ) ) ) ) ( lambda k : 2 == sum ( table.get ( i ) == x for i in k ) and ( lambda e : len ( e ) == 1 and e [ 0 ] ) ( tuple ( i for i in k if not table.get ( i ) ) ) ) )
        return ( ( 1 , 1 ) if ( 1 , 1 ) not in table.keys() else possiblewin ( -1 ) or possiblewin ( 1 ) or ( lambda : ( lambda x : x if table.get ( x ) == None else ( lambda x : len ( x ) and x [ 0 ] ) ( tuple ( filter ( lambda x : not table.get ( x ) , permutations ( ( 0 , 2 ) ) ) ) ) ) ( ( 2 * ( i == 0 ) , 2 * ( j == 0 ) ) ) ) () or ( lambda : choice ( tuple ( filter ( lambda x : x not in table.keys() , product ( *tee ( range ( 3 ) ) ) ) ) ) ) () )
    
    iseog = lambda table : ( lambda x : len ( x ) and x [ 0 ] ) ( tuple ( filter ( lambda x : abs ( x ) == 3 , ( sum ( table [ ij ] for ij in keys if table.get ( ij ) ) for keys in lines ) ) ) ) or len ( table ) >= 9
    
    table = {}
    eog = 0
    
    while not eog :
        i , j = map ( int , input ( "введите координаты: " ) .split() )
        if ( i , j ) in table.keys() :
            print ( "эта клетка занята" )
            continue
        if i not in range ( 3 ) or j not in range ( 3 ) :
            print ( "неправильные координаты" )
            continue
        table [ i , j ] = 1
        eog = iseog ( table )
        if not eog :
            table [ aimove ( table , i , j ) ] = -1
            eog = iseog ( table )
        for ij in product ( *tee ( range ( 3 ) ) ) :
            print ( ( " " , "x" , "o" ) [ table.get ( ij ) or 0 ] , end = ( " | " , " | " , "\n" ) [ ij [ 1 ] ] )
            if ij [ 0 ] < 2 and ij [ 1 ] == 2 :
                print ( "--+---+--" )
    
    print ( ( "ничья. тебе везёт ( пока что )" , "ты победил. ах ты жульник!" , "ты продул, а я победил. бе-бе-бе!" ) [ eog // 3 ] )

    Лямбда. Лямбда. Хуямбда.

    yet_another_one_shit, 27 Апреля 2018

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

    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
    class Task:
    
        def set_activity( activity_method ):
            # проанализировать исходный код activity_method 
            # разделить цепочку команд на N частей
            pass
    
        def _get_parts_number():
            return N
    
        def _run_part( part_num ):
            # выполнить часть part_num
            pass
    
    
    def run(tasks):
    
        execution = True
        part_num = 0
        while execution:
            execution = False
            for task in tasks:
                if part_num < task._get_parts_number():
                    task._run_part( part_num )
                    execution = True
            part_num += 1

    Попросил коллегу реализовать concurrency многозадачность, он на питоне нагавнякал такое.

    ded_mazay, 21 Апреля 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    def create_delta(self, timestamp, subs: set):
        sym_subs = subs.symmetric_difference(self.subs)
        added_subs = sym_subs.difference(self.subs)
        removed_subs = sym_subs.difference(subs)
        return DeltaEntry(timestamp, added_subs, removed_subs)

    gost, 21 Апреля 2018

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

    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
    def calc ( x ) :
        if type ( x ) is not list :
            return x
        if len ( x ) == 0 :
            return x
        while type ( x [ 0 ] ) is list :
            x = x [ 0 ] + x [ 1: ]
        c = x [ 0 ]
        print ( x )
        if c == 'I' :
            if len ( x ) <= 1 :
                return x
            return calc ( x [ 1: ] )
        elif c == 'K' :
            if len ( x ) <= 2 :
                return x
            return calc ( [ x[1] ] + x [ 3: ] )
        elif c == 'W' :
            if len ( x ) <= 2 :
                return x
            return calc ( x[1:3] + x[ 2: ] )
        elif c == 'S' :
            if len ( x ) <= 3 :
                return x
            return calc ( [ x[1] , x [3] , [ x[2] , x[3] ] ] + x [ 4: ] )
        elif c == 'B' :
            if len ( x ) <= 3 :
                return x
            return calc ( [ x[1] , [ x[2] , x[3] ] ] + x[4:] )
        elif c == 'C' :
            if len ( x ) <= 3 :
                return x
            return calc ( [ x[1] , x[3] , x[2] ] + x[ 4 : ] )
        return [ c ] + calc ( x [ 1: ] )
    
    
    def parse ( s , n = 0 ) :
      res = []
      i = n
      while i < len ( s ) :
        if s [ i ] == '(' :
          t = parse ( s , i + 1 )
          res.append ( t [ 0 ] )
          i = t [ 1 ] - 1
        elif s [ i ] == ')' :
          return ( res , i + 1 )
        else :
          res.append ( s [ i ] )
        i += 1
      return ( res , i )
    
    print ( '>> ' , end = '' )
    while True :
        for i in calc ( parse ( input() ) [ 0 ] ) :
            print ( i , end = '' )
        print ( '\n>> ' , end = '' )

    Вычисляэ комбинаторныэ термы, и выдаё промежности, типа:

    >> S(SKK)(SKK)x
    ['S', ['S', 'K', 'K'], ['S', 'K', 'K'], 'x']
    ['S', 'K', 'K', 'x', [['S', 'K', 'K'], 'x']]
    ['K', 'x', ['K', 'x'], [['S', 'K', 'K'], 'x']]
    ['x', [['S', 'K', 'K'], 'x']]
    ['S', 'K', 'K', 'x']
    ['K', 'x', ['K', 'x']]
    ['x']
    xx

    yet_another_one_shit, 16 Апреля 2018

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

    −2

    1. 1
    2. 2
    3. 3
    editText_url = tk.Entry(root)
    editText_url.bind(SEQ_FOCUS_IN, lambda e: editText_url.delete('0', 'end') if editText_url.get() == url_placeholder else "")
    editText_url.bind(SEQ_FOCUS_OUT, lambda e: editText_url.insert(0, url_placeholder) if len(editText_url.get()) == 0 else "")

    В tkinter нет EditText с плейсхолдером, выкручиваемся как можем!
    А еще в лямбде нельзя использовать if, зато можно тернарный оператор. `else` здесь беесполезен~

    saber-nyan, 10 Апреля 2018

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

    +1

    1. 1
    y = deepcopy(np.array(np.matrix(self.data['mg']).flatten().tolist()[0]))

    Преобразование колонки Pandas DataFrame в NumPy Array. Люблю машинное обучение.

    mizabrik, 28 Марта 2018

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

    +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
    class _automodule(types.ModuleType):
        """Automatically import lexers."""
    
        def __getattr__(self, name):
            info = LEXERS.get(name)
            if info:
                _load_lexers(info[0])
                cls = _lexer_cache[info[1]]
                setattr(self, name, cls)
                return cls
            raise AttributeError(name)
    
    
    oldmod = sys.modules[__name__]
    newmod = _automodule(__name__)
    newmod.__dict__.update(oldmod.__dict__)
    sys.modules[__name__] = newmod
    del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types

    Динамичненько!

    syoma, 28 Марта 2018

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