never-gonna-give-beep-up

Never Gonna Give You Up but it's played on a PC speaker using the beep command

  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
with open('nevergonnagiveyouup.ino') as f:
    lines = f.readlines()

note_to_freq = {}

tempo = 150

with open('rickroll.sh', 'w') as f:
    for line in lines:
        if '#define' in line:
            split = line.split()
            note_to_freq[split[1]] = split[2]
        elif 'NOTE' in line:
            split = line.split(',')
            note = True
            for word in split:
                word = word.replace(' ', '')
                print(word)
                if '//' in word or word == '\n':
                    continue
                elif 'NOTE' in word:
                    f.write(f'beep -f {note_to_freq[word]}')
                    note = True
                elif 'REST' in word:
                    f.write('sleep')
                    note = False
                else:
                    d = int(word)
                    if d < 0:
                        d /= -1.5
                    l = (60000 * 4)/tempo/d
                    if note:
                        f.write(f' -l {l}\n')
                    else:
                        f.write(f' {l/1000}\n')