Змея / Говнокод #7153 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
import os
import codecs
from xml.dom import minidom

dir = 'C:\\Users\\pee\\AppData\\Roaming\\Thunderbird\\Profiles\\your_profile_here.default\\extensions'
target = 'install.rdf'
TB_id = '{3550f703-e582-4d05-9a08-453d09bdfdc6}'
maxVer = '5.*'

# open file, parse xml, find Thunderbird ID, change maxVersion, save file
def verchanger(rdf):
    found = False
    print(rdf)
    xmldoc = minidom.parse(rdf)
    idlist = xmldoc.getElementsByTagName("em:id")
    for i in idlist:
        if i._get_firstChild().nodeValue == TB_id:
            print('Thunderbird ID was founded in em:id node with index ', idlist.index(i)+1)
            print(i.parentNode.getElementsByTagName("em:maxVersion")[0]._get_firstChild().nodeValue)
            if i.parentNode.getElementsByTagName("em:maxVersion")[0]._get_firstChild().nodeValue == maxVer:
                print('file already updated, skipping')
                break
            else:
                found = True
                i.parentNode.getElementsByTagName("em:maxVersion")[0]._get_firstChild().nodeValue = maxVer
            print('new value is: ', i.parentNode.getElementsByTagName("em:maxVersion")[0]._get_firstChild().nodeValue )
    if found:
        xmldoc.writexml(codecs.open(rdf,'w','utf-8'), encoding='utf-8')


# get list of files with full paths
filelist = [dir + '\\' + x + '\\' + target for x in os.listdir(dir)]

for i in filelist:
    verchanger(i)

Мой первый говнокод :)

Проходит по папке с расширениями Thunderbird, изменяя требуемую минимальную версию плагина на железно заданную maxVer. Вынужденно наговнокодено после обновления ТБ на версию 5.

Прошу разобрать по косточкам, я Питон только изучаю. Дочитал Лутца до классов, почти всё накопал с помощью Гугля .

omgiafs omgiafs, (Updated )

Комментарии (21, +21)

Змея / Говнокод #6914 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
  98. 98
  99. 99
  100. 100
# -*- coding: utf-8 -*-
import pyaudio
import wave
import sys
import httplib, urllib
import os
import urllib2
import json
import win32clipboard
import locale
import win32con
import win32api
import pythoncom, pyHook
import msvcrt
import time
import random
import thread
import os 

encoding = locale.getpreferredencoding(do_setlocale=True)


#while True:
#    if msvcrt.kbhit():              # Нажата ли клавиша?
#        key = ord(msvcrt.getch())   # Какая клавиша нажата?
#        print key 
#        if key == 13:               # если Enter:
#            break                                   

# Shift
#Виртуальный код:  160
#Скан-код:  42
#Ascii-код:  0
#==========

# Alt
#Виртуальный код:  164
#Скан-код:  56
#Ascii-код:  0
#==========

# Ctrl
#Виртуальный код:  162
#Скан-код:  29
#Ascii-код:  0
#==========

# z
# Alt+z
#Виртуальный код:  90
#Скан-код:  44
#Ascii-код:  122
#==========

# Ctrl+z
#Виртуальный код:  90
#Скан-код:  44
#Ascii-код:  26
#==========

# Shift+z
#Виртуальный код:  90
#Скан-код:  44
#Ascii-код:  90
#==========
#Ctrl+~ 192 41 0
def OnKeyDown(event):
    global record
    # если была нажата клавиаша, за
    if event.WindowName == None:
        wnd = 'None'
    else:
        wnd = unicode(event.WindowName, 'cp1251')
    #print u'Окно: ', wnd
    
    #if event.IsExtended():
    #    print 'IsExtended'
    #if event.IsAlt():
    #    print 'ALT'
        
    #print u'Виртуальный код: ', event.KeyID
    #print u'Скан-код: ', event.ScanCode
    #print u'Ascii-код: ', event.Ascii
    
    #print '=========='
    #return True
    if event.KeyID == 162 and event.ScanCode == 29 and event.Ascii == 0:
        if record == 0:
            record = 1
            stop = [0]
            stop[0]=False

            thread.start_new_thread(processRecord,(stop,))
            #processRecord()  
        #elif record == 1:  
        #    record = 2  
    return True # возврат True для посылки события другим обработчикам

def OnKeyUp(event):
    global record

Я старался.... =)

jivoy1988 jivoy1988, (Updated )

Комментарии (10, +10)

Змея / Говнокод #6899 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
# In Django model
def processed_description(self):
    text = self.description. \
           replace('<table', '<div class="table">'
                             '<div class="bgtop"></div>'
                             '<div class="overflow"><table'). \
           replace('</table>', '</table></div>'
                               '<div class="bgbottom"></div>'
                               '</div>'). \
           replace('<th', '<th width="50%" align="left"')
    return text

Пользователь хочет редактировать контент в WYSIWYG-редакторе. Дизайнер хочет, чтобы таблицы выглядели красиво. Верстальщику для красоты нужны дополнительные div-ы. Что делает программист? Говнокодит!

zag zag, (Updated )

Комментарии (6, +6)

Змея / Говнокод #6887 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
try:
        dday = time.strftime("%d", time.localtime(os.path.getmtime(path + d))).lstrip('0')
        dmonth = time.strftime("%m", time.localtime(os.path.getmtime(path + d))).lstrip('0')
        dhour = time.strftime("%H", time.localtime(os.path.getmtime(path + d))).lstrip('0')
        dmin = time.strftime("%M", time.localtime(os.path.getmtime(path + d))).lstrip('0')
        screenpath = os.listdir(spath)
        for screen in screenpath:
            sday = time.strftime("%d", time.localtime(os.path.getmtime(spath + screen))).lstrip('0')
            smonth = time.strftime("%m", time.localtime(os.path.getmtime(spath + screen))).lstrip('0')
            shour = time.strftime("%H", time.localtime(os.path.getmtime(spath + screen))).lstrip('0')
            smin = time.strftime("%M", time.localtime(os.path.getmtime(spath + screen))).lstrip('0')
            if dday == sday:
                if dmonth == smonth:
                    if dhour == shour:
                        if dmin == smin:
                            scr = spath + screen
                            if scr:
                                return str(scr)
                            else:
                                return None
    except:
        return "None"

Проверка даты создания двух файлов

pztrn pztrn, (Updated )

Комментарии (7, +7)

Змея / Говнокод #6733 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
a=0
b=0
c=0
d=0
...
z=0
 
A=0
B=0
C=0
D=0
...
Z=0
ile=int(input())
while ile>0:
    pom=0
    ile-=1
    slowo=input()
    dlugosc=len(slowo)
    while dlugosc>0:
        dlugosc-=1
       
        if slowo[pom]=='a':
            a=a+1;
        if slowo[pom]=='b':
            b=b+1
        if slowo[pom]=='c':
            c=c+1
        if slowo[pom]=='d':
            d=d+1
        ...
        if slowo[pom]=='z':
             z=z+1
       
        if slowo[pom]=='A':
            A=A+1
        if slowo[pom]=='B':
            B=B+1
        if slowo[pom]=='C':
            C=C+1
        if slowo[pom]=='D':
            D=D+1
        ...
        if slowo[pom]=='Z':
            Z=Z+1
               
        pom+=1
   
if(a>0):
    print('a', a)
if(b>0):
    print('b', b)
if(c>0):
    print('c', c)
if(d>0):
    print('d', d)
...
if(z>0):
    print('z', z)
 
if(A>0):
    print('A', A)
if(B>0):
    print('B', B)
if(C>0):
    print('C', C)
if(D>0):
    print('D', D)
...
if(Z>0):
    print('Z', Z)

Чел походу не знает о существовании массивов и циклов.
... заменено, уж больно код длинный.
Типичный пример китайского кода.
Оригинал - http://ideone.com/kkZ51,8lrxt

З.Ы. Да, в питоне не массивы, а списки, но так понятнее

pabloid pabloid, (Updated )

Комментарии (9, +9)

Змея / Говнокод #6722 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
a=[1,4,6,3,4,5,6,6,7,7,9,9,4,3,4,7,7,7,4,3,5,7,3,6,3,]
print a
 
def removeDoubles(a):
  nonD=range(len(a))
  for i in range(len(a)):
    for j in range(i+1,len(a)):
      if a[i]==a[j]:
        nonD.remove(i)
        break
  b=[]
  for i in nonD:
    b.append(a[i])
  return b
 
def removeDoubles2(a):
  #b=sorted(a)
  def quickSort(a):
    def qSort(i,j):
      global a
      if j==i:
        return
      elif j-i==1:
        if a[i]>a[j]:
          c=a[j]
          a[j]=a[i]
          a[i]=c
          return
      else:
        l=(j+i)/2
        qSort(i,l)
        qSort(l+1,j)
        join(i,l,j)
        return
    def join(i,l,j):
        global a
        k=i
        n=l+1
        m=0
        s=j
        t=l
        b=range(j-i+1)
        while 1:
          if a[k]<a[n]:
            z=k
            k=n
            n=z
            z=s
            s=t
            t=z
          b[m]=a[n]
          m+=1
          n+=1
          if n>s:
            for g in range(t-k+1):
                b[m+g]=a[k+g]
            break
        for g in range(j-i+1):
          a[i+g]=b[g]
    qSort(0,len(a)-1)
  c=a
  quickSort(c)
  b=[]
  b.append(c[0])
  for i in range(1,len(c)):
    if c[i]>c[i-1]:
      b.append(c[i])
  return b
 
print removeDoubles(a)
print removeDoubles2(a)

Удаление дублей из массива. Взято отсюда:
http://www.0chan.ru/c/res/181489.html

Govnocoder#0xFF Govnocoder#0xFF, (Updated )

Комментарии (22, +22)