Advertisement
Guest User

trumpgenscraper

a guest
Sep 19th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 40.15 KB | None | 0 0
  1. import urllib2
  2. import re
  3. import time
  4. import os
  5.  
  6. html_content = urllib2.urlopen('https://a.4cdn.org/pol/catalog.json').read()
  7.  
  8. trumpmatches = re.findall('TRUMP GENERAL', html_content);
  9.  
  10. s = html_content
  11. programrun = 0
  12.  
  13. while programrun == 0:
  14.  
  15.     if len(trumpmatches) == 0:
  16.         print 'TRUMP GENERAL is NOT active'
  17.     else:
  18.         print 'Found at least one TRUMP GENERAL'
  19.  
  20.  
  21.         def find_between(s, first, last):
  22.             try:
  23.                 start = s.index(first) + len(first)
  24.                 end = s.index(last, start)
  25.                 return s[start:end]
  26.             except ValueError:
  27.                 return ""
  28.  
  29.  
  30.         page1 = find_between(s, '[{"page":1,"threads":[{"no":', ',{"page":2,')
  31.  
  32.         fpage1 = '{"page":1,"threads":[{"no":'
  33.         fpage1 += page1
  34.         fpage1 += '},'
  35.  
  36.         print 'P1 ' + fpage1
  37.  
  38.  
  39.         def find_between(s, first, last):
  40.             try:
  41.                 start = s.index(first) + len(first)
  42.                 end = s.index(last, start)
  43.                 return s[start:end]
  44.             except ValueError:
  45.                 return ""
  46.  
  47.  
  48.         page2 = find_between(s, '{"page":2,"threads":[{"no":', ',{"page":3,')
  49.  
  50.         fpage2 = '{"page":2,"threads":[{"no":'
  51.         fpage2 += page2
  52.         fpage2 += '},'
  53.  
  54.         print 'P2 ' + fpage2
  55.  
  56.  
  57.         def find_between(s, first, last):
  58.             try:
  59.                 start = s.index(first) + len(first)
  60.                 end = s.index(last, start)
  61.                 return s[start:end]
  62.             except ValueError:
  63.                 return ""
  64.  
  65.  
  66.         page3 = find_between(s, '{"page":3,"threads":[{"no":', ',{"page":4,')
  67.  
  68.         fpage3 = '{"page":3,"threads":[{"no":'
  69.         fpage3 += page3
  70.         fpage3 += '},'
  71.  
  72.         print 'P3 ' + fpage3
  73.  
  74.  
  75.         def find_between(s, first, last):
  76.             try:
  77.                 start = s.index(first) + len(first)
  78.                 end = s.index(last, start)
  79.                 return s[start:end]
  80.             except ValueError:
  81.                 return ""
  82.  
  83.  
  84.         page4 = find_between(s, '{"page":4,"threads":[{"no":', ',{"page":5,')
  85.  
  86.         fpage4 = '{"page":4,"threads":[{"no":'
  87.         fpage4 += page4
  88.         fpage4 += '},'
  89.  
  90.         print 'P4 ' + fpage4
  91.  
  92.  
  93.         def find_between(s, first, last):
  94.             try:
  95.                 start = s.index(first) + len(first)
  96.                 end = s.index(last, start)
  97.                 return s[start:end]
  98.             except ValueError:
  99.                 return ""
  100.  
  101.  
  102.         page5 = find_between(s, '{"page":5,"threads":[{"no":', ',{"page":6,')
  103.  
  104.         fpage5 = '{"page":5,"threads":[{"no":'
  105.         fpage5 += page5
  106.         fpage5 += '},'
  107.  
  108.         print 'P5 ' + fpage5
  109.  
  110.  
  111.         def find_between(s, first, last):
  112.             try:
  113.                 start = s.index(first) + len(first)
  114.                 end = s.index(last, start)
  115.                 return s[start:end]
  116.             except ValueError:
  117.                 return ""
  118.  
  119.  
  120.         page6 = find_between(s, '{"page":6,"threads":[{"no":', ',{"page":7,')
  121.  
  122.         fpage6 = '{"page":6,"threads":[{"no":'
  123.         fpage6 += page6
  124.         fpage6 += '},'
  125.  
  126.         print 'P6 ' + fpage6
  127.  
  128.  
  129.         def find_between(s, first, last):
  130.             try:
  131.                 start = s.index(first) + len(first)
  132.                 end = s.index(last, start)
  133.                 return s[start:end]
  134.             except ValueError:
  135.                 return ""
  136.  
  137.  
  138.         page7 = find_between(s, '{"page":7,"threads":[{"no":', ',{"page":8,')
  139.  
  140.         fpage7 = '{"page":7,"threads":[{"no":'
  141.         fpage7 += page7
  142.         fpage7 += '},'
  143.  
  144.         print 'P7 ' + fpage7
  145.  
  146.  
  147.         def find_between(s, first, last):
  148.             try:
  149.                 start = s.index(first) + len(first)
  150.                 end = s.index(last, start)
  151.                 return s[start:end]
  152.             except ValueError:
  153.                 return ""
  154.  
  155.  
  156.         page8 = find_between(s, '{"page":8,"threads":[{"no":', ',{"page":9,')
  157.  
  158.         fpage8 = '{"page":8,"threads":[{"no":'
  159.         fpage8 += page8
  160.         fpage8 += '},'
  161.  
  162.         print 'P8 ' + fpage8
  163.  
  164.  
  165.         def find_between(s, first, last):
  166.             try:
  167.                 start = s.index(first) + len(first)
  168.                 end = s.index(last, start)
  169.                 return s[start:end]
  170.             except ValueError:
  171.                 return ""
  172.  
  173.  
  174.         page9 = find_between(s, '{"page":9,"threads":[{"no":', ',{"page":10,')
  175.  
  176.         fpage9 = '{"page":9,"threads":[{"no":'
  177.         fpage9 += page9
  178.         fpage9 += '},'
  179.  
  180.         print 'P9 ' + fpage9
  181.  
  182.  
  183.         def find_between(s, first, last):
  184.             try:
  185.                 start = s.index(first) + len(first)
  186.                 end = s.index(last, start)
  187.                 return s[start:end]
  188.             except ValueError:
  189.                 return ""
  190.  
  191.  
  192.         page10 = find_between(s, '{"page":10,"threads":[{"no":', ',{"page":11,')
  193.  
  194.         fpage10 = '{"page":10,"threads":[{"no":'
  195.         fpage10 += page10
  196.         fpage10 += '},'
  197.  
  198.         print '10 ' + fpage10
  199.  
  200.         if 'TRUMP GENERAL' in fpage1:
  201.             print 'TG on Page 1'
  202.             split1 = fpage1.split('TRUMP GENERAL', 1)[0] + 'TRUMP GENERAL'
  203.             split1 = split1.replace('{"page":1,"threads":[', '')
  204.  
  205.             compare1 = 1
  206.             while compare1 < 23:
  207.                 def find_between(split1, first, last):
  208.                     try:
  209.                         start = split1.index(first) + len(first)
  210.                         end = split1.index(last, start)
  211.                         return split1[start:end]
  212.                     except ValueError:
  213.                         return ""
  214.  
  215.  
  216.                 split1compare = find_between(split1, '{"no":', '"last_modified"')
  217.  
  218.                 if 'TRUMP GENERAL' in split1compare:
  219.                     print 'TRUMP GEN RAW ' + split1compare
  220.                     compare1 = 23
  221.                 else:
  222.                     split1 = split1.replace('{"no":"last_modified":', '')
  223.                     split1 = split1.replace(split1compare, '')
  224.                     compare1 += 1
  225.  
  226.  
  227.             def find_between(split1, first, last):
  228.                 try:
  229.                     start = split1.index(first) + len(first)
  230.                     end = split1.index(last, start)
  231.                     return split1[start:end]
  232.                 except ValueError:
  233.                     return ""
  234.  
  235.  
  236.             split1final = find_between(split1, '{"no":', 'TRUMP GENERAL')
  237.             split1final = split1final[0:8]
  238.  
  239.             print 'TG thread id found: ' + split1final
  240.  
  241.             if split1final in open("C:\TrumpGeneral1.txt").read():
  242.                 print 'General already in Slot 1'
  243.             elif split1final in open("C:\TrumpGeneral2.txt").read():
  244.                 print 'General already in Slot 2'
  245.             elif split1final in open("C:\TrumpGeneral3.txt").read():
  246.                 print 'General already in Slot 3'
  247.             elif split1final in open("C:\TrumpGeneral4.txt").read():
  248.                 print 'General already in Slot 4'
  249.             elif split1final in open("C:\TrumpGeneral5.txt").read():
  250.                 print 'General already in Slot 5'
  251.             else:
  252.                 if os.stat("C:\TrumpGeneral1.txt").st_size == 0:
  253.                     text_file = open("C:\TrumpGeneral1.txt", "w")
  254.                     text_file.write(split1final)
  255.                     text_file.close()
  256.                     print 'Wrote ' + split1final + ' to TrumpGeneral1'
  257.                 elif os.stat("C:\TrumpGeneral2.txt").st_size == 0:
  258.                     text_file = open("C:\TrumpGeneral2.txt", "w")
  259.                     text_file.write(split1final)
  260.                     text_file.close()
  261.                     print 'Wrote ' + split1final + ' to TrumpGeneral2'
  262.                 elif os.stat("C:\TrumpGeneral3.txt").st_size == 0:
  263.                     text_file = open("C:\TrumpGeneral3.txt", "w")
  264.                     text_file.write(split1final)
  265.                     text_file.close()
  266.                     print 'Wrote ' + split1final + ' to TrumpGeneral3'
  267.                 elif os.stat("C:\TrumpGeneral4.txt").st_size == 0:
  268.                     text_file = open("C:\TrumpGeneral4.txt", "w")
  269.                     text_file.write(split1final)
  270.                     text_file.close()
  271.                     print 'Wrote ' + split1final + ' to TrumpGeneral4'
  272.                 else:
  273.                     text_file = open("C:\TrumpGeneral5.txt", "w")
  274.                     text_file.write(split1final)
  275.                     text_file.close()
  276.                     print 'Wrote ' + split1final + ' to TrumpGeneral5'
  277.  
  278.         if 'TRUMP GENERAL' in fpage2:
  279.             print 'TG on Page 2'
  280.             split2 = fpage2.split('TRUMP GENERAL', 2)[0] + 'TRUMP GENERAL'
  281.             split2 = split2.replace('{"page":2,"threads":[', '')
  282.  
  283.             compare2 = 1
  284.             while compare2 < 23:
  285.                 def find_between(split2, first, last):
  286.                     try:
  287.                         start = split2.index(first) + len(first)
  288.                         end = split2.index(last, start)
  289.                         return split2[start:end]
  290.                     except ValueError:
  291.                         return ""
  292.  
  293.  
  294.                 split2compare = find_between(split2, '{"no":', '"last_modified"')
  295.  
  296.                 if 'TRUMP GENERAL' in split2compare:
  297.                     print 'TRUMP GEN RAW ' + split2compare
  298.                     compare2 = 23
  299.                 else:
  300.                     split2 = split2.replace('{"no":"last_modified":', '')
  301.                     split2 = split2.replace(split2compare, '')
  302.                     compare2 += 1
  303.  
  304.  
  305.             def find_between(split2, first, last):
  306.                 try:
  307.                     start = split2.index(first) + len(first)
  308.                     end = split2.index(last, start)
  309.                     return split2[start:end]
  310.                 except ValueError:
  311.                     return ""
  312.  
  313.  
  314.             split2final = find_between(split2, '{"no":', 'TRUMP GENERAL')
  315.             split2final = split2final[0:8]
  316.  
  317.             print 'TG thread id found: ' + split2final
  318.  
  319.             if split2final in open("C:\TrumpGeneral1.txt").read():
  320.                 print 'General already in Slot 1'
  321.             elif split2final in open("C:\TrumpGeneral2.txt").read():
  322.                 print 'General already in Slot 2'
  323.             elif split2final in open("C:\TrumpGeneral3.txt").read():
  324.                 print 'General already in Slot 3'
  325.             elif split2final in open("C:\TrumpGeneral4.txt").read():
  326.                 print 'General already in Slot 4'
  327.             elif split2final in open("C:\TrumpGeneral5.txt").read():
  328.                 print 'General already in Slot 5'
  329.             else:
  330.                 if os.stat("C:\TrumpGeneral1.txt").st_size == 0:
  331.                     text_file = open("C:\TrumpGeneral1.txt", "w")
  332.                     text_file.write(split2final)
  333.                     text_file.close()
  334.                     print 'Wrote ' + split2final + ' to TrumpGeneral1'
  335.                 elif os.stat("C:\TrumpGeneral2.txt").st_size == 0:
  336.                     text_file = open("C:\TrumpGeneral2.txt", "w")
  337.                     text_file.write(split2final)
  338.                     text_file.close()
  339.                     print 'Wrote ' + split2final + ' to TrumpGeneral2'
  340.                 elif os.stat("C:\TrumpGeneral3.txt").st_size == 0:
  341.                     text_file = open("C:\TrumpGeneral3.txt", "w")
  342.                     text_file.write(split2final)
  343.                     text_file.close()
  344.                     print 'Wrote ' + split2final + ' to TrumpGeneral3'
  345.                 elif os.stat("C:\TrumpGeneral4.txt").st_size == 0:
  346.                     text_file = open("C:\TrumpGeneral4.txt", "w")
  347.                     text_file.write(split2final)
  348.                     text_file.close()
  349.                     print 'Wrote ' + split2final + ' to TrumpGeneral4'
  350.                 else:
  351.                     text_file = open("C:\TrumpGeneral5.txt", "w")
  352.                     text_file.write(split2final)
  353.                     text_file.close()
  354.                     print 'Wrote ' + split2final + ' to TrumpGeneral5'
  355.  
  356.         if 'TRUMP GENERAL' in fpage3:
  357.             print 'TG on Page 3'
  358.             split3 = fpage3.split('TRUMP GENERAL', 3)[0] + 'TRUMP GENERAL'
  359.             split3 = split3.replace('{"page":3,"threads":[', '')
  360.  
  361.             compare3 = 1
  362.             while compare3 < 23:
  363.                 def find_between(split3, first, last):
  364.                     try:
  365.                         start = split3.index(first) + len(first)
  366.                         end = split3.index(last, start)
  367.                         return split3[start:end]
  368.                     except ValueError:
  369.                         return ""
  370.  
  371.  
  372.                 split3compare = find_between(split3, '{"no":', '"last_modified"')
  373.  
  374.                 if 'TRUMP GENERAL' in split3compare:
  375.                     print 'TRUMP GEN RAW ' + split3compare
  376.                     compare3 = 23
  377.                 else:
  378.                     split3 = split3.replace('{"no":"last_modified":', '')
  379.                     split3 = split3.replace(split3compare, '')
  380.                     compare3 += 1
  381.  
  382.  
  383.             def find_between(split3, first, last):
  384.                 try:
  385.                     start = split3.index(first) + len(first)
  386.                     end = split3.index(last, start)
  387.                     return split3[start:end]
  388.                 except ValueError:
  389.                     return ""
  390.  
  391.  
  392.             split3final = find_between(split3, '{"no":', 'TRUMP GENERAL')
  393.             split3final = split3final[0:8]
  394.  
  395.             print 'TG thread id found: ' + split3final
  396.  
  397.             if split3final in open("C:\TrumpGeneral1.txt").read():
  398.                 print 'General already in Slot 1'
  399.             elif split3final in open("C:\TrumpGeneral2.txt").read():
  400.                 print 'General already in Slot 2'
  401.             elif split3final in open("C:\TrumpGeneral3.txt").read():
  402.                 print 'General already in Slot 3'
  403.             elif split3final in open("C:\TrumpGeneral4.txt").read():
  404.                 print 'General already in Slot 4'
  405.             elif split3final in open("C:\TrumpGeneral5.txt").read():
  406.                 print 'General already in Slot 5'
  407.             else:
  408.                 if os.stat("C:\TrumpGeneral1.txt").st_size == 0:
  409.                     text_file = open("C:\TrumpGeneral1.txt", "w")
  410.                     text_file.write(split3final)
  411.                     text_file.close()
  412.                     print 'Wrote ' + split3final + ' to TrumpGeneral1'
  413.                 elif os.stat("C:\TrumpGeneral2.txt").st_size == 0:
  414.                     text_file = open("C:\TrumpGeneral2.txt", "w")
  415.                     text_file.write(split3final)
  416.                     text_file.close()
  417.                     print 'Wrote ' + split3final + ' to TrumpGeneral2'
  418.                 elif os.stat("C:\TrumpGeneral3.txt").st_size == 0:
  419.                     text_file = open("C:\TrumpGeneral3.txt", "w")
  420.                     text_file.write(split3final)
  421.                     text_file.close()
  422.                     print 'Wrote ' + split3final + ' to TrumpGeneral3'
  423.                 elif os.stat("C:\TrumpGeneral4.txt").st_size == 0:
  424.                     text_file = open("C:\TrumpGeneral4.txt", "w")
  425.                     text_file.write(split3final)
  426.                     text_file.close()
  427.                     print 'Wrote ' + split3final + ' to TrumpGeneral4'
  428.                 else:
  429.                     text_file = open("C:\TrumpGeneral5.txt", "w")
  430.                     text_file.write(split3final)
  431.                     text_file.close()
  432.                     print 'Wrote ' + split3final + ' to TrumpGeneral5'
  433.  
  434.         if 'TRUMP GENERAL' in fpage4:
  435.             print 'TG on Page 4'
  436.             split4 = fpage4.split('TRUMP GENERAL', 4)[0] + 'TRUMP GENERAL'
  437.             split4 = split4.replace('{"page":4,"threads":[', '')
  438.  
  439.             compare4 = 1
  440.             while compare4 < 23:
  441.                 def find_between(split4, first, last):
  442.                     try:
  443.                         start = split4.index(first) + len(first)
  444.                         end = split4.index(last, start)
  445.                         return split4[start:end]
  446.                     except ValueError:
  447.                         return ""
  448.  
  449.  
  450.                 split4compare = find_between(split4, '{"no":', '"last_modified"')
  451.  
  452.                 if 'TRUMP GENERAL' in split4compare:
  453.                     print 'TRUMP GEN RAW ' + split4compare
  454.                     compare4 = 23
  455.                 else:
  456.                     split4 = split4.replace('{"no":"last_modified":', '')
  457.                     split4 = split4.replace(split4compare, '')
  458.                     compare4 += 1
  459.  
  460.  
  461.             def find_between(split4, first, last):
  462.                 try:
  463.                     start = split4.index(first) + len(first)
  464.                     end = split4.index(last, start)
  465.                     return split4[start:end]
  466.                 except ValueError:
  467.                     return ""
  468.  
  469.  
  470.             split4final = find_between(split4, '{"no":', 'TRUMP GENERAL')
  471.             split4final = split4final[0:8]
  472.  
  473.             print 'TG thread id found: ' + split4final
  474.  
  475.             if split4final in open("C:\TrumpGeneral1.txt").read():
  476.                 print 'General already in Slot 1'
  477.             elif split4final in open("C:\TrumpGeneral2.txt").read():
  478.                 print 'General already in Slot 2'
  479.             elif split4final in open("C:\TrumpGeneral3.txt").read():
  480.                 print 'General already in Slot 3'
  481.             elif split4final in open("C:\TrumpGeneral4.txt").read():
  482.                 print 'General already in Slot 4'
  483.             elif split4final in open("C:\TrumpGeneral5.txt").read():
  484.                 print 'General already in Slot 5'
  485.             else:
  486.                 if os.stat("C:\TrumpGeneral1.txt").st_size == 0:
  487.                     text_file = open("C:\TrumpGeneral1.txt", "w")
  488.                     text_file.write(split4final)
  489.                     text_file.close()
  490.                     print 'Wrote ' + split4final + ' to TrumpGeneral1'
  491.                 elif os.stat("C:\TrumpGeneral2.txt").st_size == 0:
  492.                     text_file = open("C:\TrumpGeneral2.txt", "w")
  493.                     text_file.write(split4final)
  494.                     text_file.close()
  495.                     print 'Wrote ' + split4final + ' to TrumpGeneral2'
  496.                 elif os.stat("C:\TrumpGeneral3.txt").st_size == 0:
  497.                     text_file = open("C:\TrumpGeneral3.txt", "w")
  498.                     text_file.write(split4final)
  499.                     text_file.close()
  500.                     print 'Wrote ' + split4final + ' to TrumpGeneral3'
  501.                 elif os.stat("C:\TrumpGeneral4.txt").st_size == 0:
  502.                     text_file = open("C:\TrumpGeneral4.txt", "w")
  503.                     text_file.write(split4final)
  504.                     text_file.close()
  505.                     print 'Wrote ' + split4final + ' to TrumpGeneral4'
  506.                 else:
  507.                     text_file = open("C:\TrumpGeneral5.txt", "w")
  508.                     text_file.write(split4final)
  509.                     text_file.close()
  510.                     print 'Wrote ' + split4final + ' to TrumpGeneral5'
  511.  
  512.         if 'TRUMP GENERAL' in fpage5:
  513.             print 'TG on Page 5'
  514.             split5 = fpage5.split('TRUMP GENERAL', 5)[0] + 'TRUMP GENERAL'
  515.             split5 = split5.replace('{"page":5,"threads":[', '')
  516.  
  517.             compare5 = 1
  518.             while compare5 < 23:
  519.                 def find_between(split5, first, last):
  520.                     try:
  521.                         start = split5.index(first) + len(first)
  522.                         end = split5.index(last, start)
  523.                         return split5[start:end]
  524.                     except ValueError:
  525.                         return ""
  526.  
  527.  
  528.                 split5compare = find_between(split5, '{"no":', '"last_modified"')
  529.  
  530.                 if 'TRUMP GENERAL' in split5compare:
  531.                     print 'TRUMP GEN RAW ' + split5compare
  532.                     compare5 = 23
  533.                 else:
  534.                     split5 = split5.replace('{"no":"last_modified":', '')
  535.                     split5 = split5.replace(split5compare, '')
  536.                     compare5 += 1
  537.  
  538.  
  539.             def find_between(split5, first, last):
  540.                 try:
  541.                     start = split5.index(first) + len(first)
  542.                     end = split5.index(last, start)
  543.                     return split5[start:end]
  544.                 except ValueError:
  545.                     return ""
  546.  
  547.  
  548.             split5final = find_between(split5, '{"no":', 'TRUMP GENERAL')
  549.             split5final = split5final[0:8]
  550.  
  551.             print 'TG thread id found: ' + split5final
  552.  
  553.             if split5final in open("C:\TrumpGeneral1.txt").read():
  554.                 print 'General already in Slot 1'
  555.             elif split5final in open("C:\TrumpGeneral2.txt").read():
  556.                 print 'General already in Slot 2'
  557.             elif split5final in open("C:\TrumpGeneral3.txt").read():
  558.                 print 'General already in Slot 3'
  559.             elif split5final in open("C:\TrumpGeneral4.txt").read():
  560.                 print 'General already in Slot 4'
  561.             elif split5final in open("C:\TrumpGeneral5.txt").read():
  562.                 print 'General already in Slot 5'
  563.             else:
  564.                 if os.stat("C:\TrumpGeneral1.txt").st_size == 0:
  565.                     text_file = open("C:\TrumpGeneral1.txt", "w")
  566.                     text_file.write(split5final)
  567.                     text_file.close()
  568.                     print 'Wrote ' + split5final + ' to TrumpGeneral1'
  569.                 elif os.stat("C:\TrumpGeneral2.txt").st_size == 0:
  570.                     text_file = open("C:\TrumpGeneral2.txt", "w")
  571.                     text_file.write(split5final)
  572.                     text_file.close()
  573.                     print 'Wrote ' + split5final + ' to TrumpGeneral2'
  574.                 elif os.stat("C:\TrumpGeneral3.txt").st_size == 0:
  575.                     text_file = open("C:\TrumpGeneral3.txt", "w")
  576.                     text_file.write(split5final)
  577.                     text_file.close()
  578.                     print 'Wrote ' + split5final + ' to TrumpGeneral3'
  579.                 elif os.stat("C:\TrumpGeneral4.txt").st_size == 0:
  580.                     text_file = open("C:\TrumpGeneral4.txt", "w")
  581.                     text_file.write(split5final)
  582.                     text_file.close()
  583.                     print 'Wrote ' + split5final + ' to TrumpGeneral4'
  584.                 else:
  585.                     text_file = open("C:\TrumpGeneral5.txt", "w")
  586.                     text_file.write(split5final)
  587.                     text_file.close()
  588.                     print 'Wrote ' + split5final + ' to TrumpGeneral5'
  589.  
  590.         if 'TRUMP GENERAL' in fpage6:
  591.             print 'TG on Page 6'
  592.             split6 = fpage6.split('TRUMP GENERAL', 6)[0] + 'TRUMP GENERAL'
  593.             split6 = split6.replace('{"page":6,"threads":[', '')
  594.  
  595.             compare6 = 1
  596.             while compare6 < 23:
  597.                 def find_between(split6, first, last):
  598.                     try:
  599.                         start = split6.index(first) + len(first)
  600.                         end = split6.index(last, start)
  601.                         return split6[start:end]
  602.                     except ValueError:
  603.                         return ""
  604.  
  605.  
  606.                 split6compare = find_between(split6, '{"no":', '"last_modified"')
  607.  
  608.                 if 'TRUMP GENERAL' in split6compare:
  609.                     print 'TRUMP GEN RAW ' + split6compare
  610.                     compare6 = 23
  611.                 else:
  612.                     split6 = split6.replace('{"no":"last_modified":', '')
  613.                     split6 = split6.replace(split6compare, '')
  614.                     compare6 += 1
  615.  
  616.  
  617.             def find_between(split6, first, last):
  618.                 try:
  619.                     start = split6.index(first) + len(first)
  620.                     end = split6.index(last, start)
  621.                     return split6[start:end]
  622.                 except ValueError:
  623.                     return ""
  624.  
  625.  
  626.             split6final = find_between(split6, '{"no":', 'TRUMP GENERAL')
  627.             split6final = split6final[0:8]
  628.  
  629.             print 'TG thread id found: ' + split6final
  630.  
  631.             if split6final in open("C:\TrumpGeneral1.txt").read():
  632.                 print 'General already in Slot 1'
  633.             elif split6final in open("C:\TrumpGeneral2.txt").read():
  634.                 print 'General already in Slot 2'
  635.             elif split6final in open("C:\TrumpGeneral3.txt").read():
  636.                 print 'General already in Slot 3'
  637.             elif split6final in open("C:\TrumpGeneral4.txt").read():
  638.                 print 'General already in Slot 4'
  639.             elif split6final in open("C:\TrumpGeneral5.txt").read():
  640.                 print 'General already in Slot 5'
  641.             else:
  642.                 if os.stat("C:\TrumpGeneral1.txt").st_size == 0:
  643.                     text_file = open("C:\TrumpGeneral1.txt", "w")
  644.                     text_file.write(split6final)
  645.                     text_file.close()
  646.                     print 'Wrote ' + split6final + ' to TrumpGeneral1'
  647.                 elif os.stat("C:\TrumpGeneral2.txt").st_size == 0:
  648.                     text_file = open("C:\TrumpGeneral2.txt", "w")
  649.                     text_file.write(split6final)
  650.                     text_file.close()
  651.                     print 'Wrote ' + split6final + ' to TrumpGeneral2'
  652.                 elif os.stat("C:\TrumpGeneral3.txt").st_size == 0:
  653.                     text_file = open("C:\TrumpGeneral3.txt", "w")
  654.                     text_file.write(split6final)
  655.                     text_file.close()
  656.                     print 'Wrote ' + split6final + ' to TrumpGeneral3'
  657.                 elif os.stat("C:\TrumpGeneral4.txt").st_size == 0:
  658.                     text_file = open("C:\TrumpGeneral4.txt", "w")
  659.                     text_file.write(split6final)
  660.                     text_file.close()
  661.                     print 'Wrote ' + split6final + ' to TrumpGeneral4'
  662.                 else:
  663.                     text_file = open("C:\TrumpGeneral5.txt", "w")
  664.                     text_file.write(split6final)
  665.                     text_file.close()
  666.                     print 'Wrote ' + split6final + ' to TrumpGeneral5'
  667.  
  668.         if 'TRUMP GENERAL' in fpage7:
  669.             print 'TG on Page 7'
  670.             split7 = fpage7.split('TRUMP GENERAL', 7)[0] + 'TRUMP GENERAL'
  671.             split7 = split7.replace('{"page":7,"threads":[', '')
  672.  
  673.             compare7 = 1
  674.             while compare7 < 23:
  675.                 def find_between(split7, first, last):
  676.                     try:
  677.                         start = split7.index(first) + len(first)
  678.                         end = split7.index(last, start)
  679.                         return split7[start:end]
  680.                     except ValueError:
  681.                         return ""
  682.  
  683.  
  684.                 split7compare = find_between(split7, '{"no":', '"last_modified"')
  685.  
  686.                 if 'TRUMP GENERAL' in split7compare:
  687.                     print 'TRUMP GEN RAW ' + split7compare
  688.                     compare7 = 23
  689.                 else:
  690.                     split7 = split7.replace('{"no":"last_modified":', '')
  691.                     split7 = split7.replace(split7compare, '')
  692.                     compare7 += 1
  693.  
  694.  
  695.             def find_between(split7, first, last):
  696.                 try:
  697.                     start = split7.index(first) + len(first)
  698.                     end = split7.index(last, start)
  699.                     return split7[start:end]
  700.                 except ValueError:
  701.                     return ""
  702.  
  703.  
  704.             split7final = find_between(split7, '{"no":', 'TRUMP GENERAL')
  705.             split7final = split7final[0:8]
  706.  
  707.             print 'TG thread id found: ' + split7final
  708.  
  709.             if split7final in open("C:\TrumpGeneral1.txt").read():
  710.                 print 'General already in Slot 1'
  711.             elif split7final in open("C:\TrumpGeneral2.txt").read():
  712.                 print 'General already in Slot 2'
  713.             elif split7final in open("C:\TrumpGeneral3.txt").read():
  714.                 print 'General already in Slot 3'
  715.             elif split7final in open("C:\TrumpGeneral4.txt").read():
  716.                 print 'General already in Slot 4'
  717.             elif split7final in open("C:\TrumpGeneral5.txt").read():
  718.                 print 'General already in Slot 5'
  719.             else:
  720.                 if os.stat("C:\TrumpGeneral1.txt").st_size == 0:
  721.                     text_file = open("C:\TrumpGeneral1.txt", "w")
  722.                     text_file.write(split7final)
  723.                     text_file.close()
  724.                     print 'Wrote ' + split7final + ' to TrumpGeneral1'
  725.                 elif os.stat("C:\TrumpGeneral2.txt").st_size == 0:
  726.                     text_file = open("C:\TrumpGeneral2.txt", "w")
  727.                     text_file.write(split7final)
  728.                     text_file.close()
  729.                     print 'Wrote ' + split7final + ' to TrumpGeneral2'
  730.                 elif os.stat("C:\TrumpGeneral3.txt").st_size == 0:
  731.                     text_file = open("C:\TrumpGeneral3.txt", "w")
  732.                     text_file.write(split7final)
  733.                     text_file.close()
  734.                     print 'Wrote ' + split7final + ' to TrumpGeneral3'
  735.                 elif os.stat("C:\TrumpGeneral4.txt").st_size == 0:
  736.                     text_file = open("C:\TrumpGeneral4.txt", "w")
  737.                     text_file.write(split7final)
  738.                     text_file.close()
  739.                     print 'Wrote ' + split7final + ' to TrumpGeneral4'
  740.                 else:
  741.                     text_file = open("C:\TrumpGeneral5.txt", "w")
  742.                     text_file.write(split7final)
  743.                     text_file.close()
  744.                     print 'Wrote ' + split7final + ' to TrumpGeneral5'
  745.  
  746.         if 'TRUMP GENERAL' in fpage8:
  747.             print 'TG on Page 8'
  748.             split8 = fpage8.split('TRUMP GENERAL', 8)[0] + 'TRUMP GENERAL'
  749.             split8 = split8.replace('{"page":8,"threads":[', '')
  750.  
  751.             compare8 = 1
  752.             while compare8 < 23:
  753.                 def find_between(split8, first, last):
  754.                     try:
  755.                         start = split8.index(first) + len(first)
  756.                         end = split8.index(last, start)
  757.                         return split8[start:end]
  758.                     except ValueError:
  759.                         return ""
  760.  
  761.                 split8compare = find_between(split8, '{"no":', '"last_modified"')
  762.  
  763.                 if 'TRUMP GENERAL' in split8compare:
  764.                     print 'TRUMP GEN RAW ' + split8compare
  765.                     compare8 = 23
  766.                 else:
  767.                     split8 = split8.replace('{"no":"last_modified":', '')
  768.                     split8 = split8.replace(split8compare, '')
  769.                     compare8 += 1
  770.  
  771.  
  772.             def find_between(split8, first, last):
  773.                 try:
  774.                     start = split8.index(first) + len(first)
  775.                     end = split8.index(last, start)
  776.                     return split8[start:end]
  777.                 except ValueError:
  778.                     return ""
  779.  
  780.  
  781.             split8final = find_between(split8, '{"no":', 'TRUMP GENERAL')
  782.             split8final = split8final[0:8]
  783.  
  784.             print 'TG thread id found: ' + split8final
  785.  
  786.             if split8final in open("C:\TrumpGeneral1.txt").read():
  787.                 print 'General already in Slot 1'
  788.             elif split8final in open("C:\TrumpGeneral2.txt").read():
  789.                 print 'General already in Slot 2'
  790.             elif split8final in open("C:\TrumpGeneral3.txt").read():
  791.                 print 'General already in Slot 3'
  792.             elif split8final in open("C:\TrumpGeneral4.txt").read():
  793.                 print 'General already in Slot 4'
  794.             elif split8final in open("C:\TrumpGeneral5.txt").read():
  795.                 print 'General already in Slot 5'
  796.             else:
  797.                 if os.stat("C:\TrumpGeneral1.txt").st_size == 0:
  798.                     text_file = open("C:\TrumpGeneral1.txt", "w")
  799.                     text_file.write(split8final)
  800.                     text_file.close()
  801.                     print 'Wrote ' + split8final + ' to TrumpGeneral1'
  802.                 elif os.stat("C:\TrumpGeneral2.txt").st_size == 0:
  803.                     text_file = open("C:\TrumpGeneral2.txt", "w")
  804.                     text_file.write(split8final)
  805.                     text_file.close()
  806.                     print 'Wrote ' + split8final + ' to TrumpGeneral2'
  807.                 elif os.stat("C:\TrumpGeneral3.txt").st_size == 0:
  808.                     text_file = open("C:\TrumpGeneral3.txt", "w")
  809.                     text_file.write(split8final)
  810.                     text_file.close()
  811.                     print 'Wrote ' + split8final + ' to TrumpGeneral3'
  812.                 elif os.stat("C:\TrumpGeneral4.txt").st_size == 0:
  813.                     text_file = open("C:\TrumpGeneral4.txt", "w")
  814.                     text_file.write(split8final)
  815.                     text_file.close()
  816.                     print 'Wrote ' + split8final + ' to TrumpGeneral4'
  817.                 else:
  818.                     text_file = open("C:\TrumpGeneral5.txt", "w")
  819.                     text_file.write(split8final)
  820.                     text_file.close()
  821.                     print 'Wrote ' + split8final + ' to TrumpGeneral5'
  822.  
  823.         if 'TRUMP GENERAL' in fpage9:
  824.             print 'TG on Page 9'
  825.             split9 = fpage9.split('TRUMP GENERAL', 9)[0] + 'TRUMP GENERAL'
  826.             split9 = split9.replace('{"page":9,"threads":[', '')
  827.  
  828.             compare9 = 1
  829.             while compare9 < 23:
  830.                 def find_between(split9, first, last):
  831.                     try:
  832.                         start = split9.index(first) + len(first)
  833.                         end = split9.index(last, start)
  834.                         return split9[start:end]
  835.                     except ValueError:
  836.                         return ""
  837.  
  838.  
  839.                 split9compare = find_between(split9, '{"no":', '"last_modified"')
  840.  
  841.                 if 'TRUMP GENERAL' in split9compare:
  842.                     print 'TRUMP GEN RAW ' + split9compare
  843.                     compare9 = 23
  844.                 else:
  845.                     split9 = split9.replace('{"no":"last_modified":', '')
  846.                     split9 = split9.replace(split9compare, '')
  847.                     compare9 += 1
  848.  
  849.  
  850.             def find_between(split9, first, last):
  851.                 try:
  852.                     start = split9.index(first) + len(first)
  853.                     end = split9.index(last, start)
  854.                     return split9[start:end]
  855.                 except ValueError:
  856.                     return ""
  857.  
  858.             split9final = find_between(split9, '{"no":', 'TRUMP GENERAL')
  859.             split9final = split9final[0:8]
  860.  
  861.             print 'TG thread id found: ' + split9final
  862.  
  863.             if split9final in open("C:\TrumpGeneral1.txt").read():
  864.                 print 'General already in Slot 1'
  865.             elif split9final in open("C:\TrumpGeneral2.txt").read():
  866.                 print 'General already in Slot 2'
  867.             elif split9final in open("C:\TrumpGeneral3.txt").read():
  868.                 print 'General already in Slot 3'
  869.             elif split9final in open("C:\TrumpGeneral4.txt").read():
  870.                 print 'General already in Slot 4'
  871.             elif split9final in open("C:\TrumpGeneral5.txt").read():
  872.                 print 'General already in Slot 5'
  873.             else:
  874.                 if os.stat("C:\TrumpGeneral1.txt").st_size == 0:
  875.                     text_file = open("C:\TrumpGeneral1.txt", "w")
  876.                     text_file.write(split9final)
  877.                     text_file.close()
  878.                     print 'Wrote ' + split9final + ' to TrumpGeneral1'
  879.                 elif os.stat("C:\TrumpGeneral2.txt").st_size == 0:
  880.                     text_file = open("C:\TrumpGeneral2.txt", "w")
  881.                     text_file.write(split9final)
  882.                     text_file.close()
  883.                     print 'Wrote ' + split9final + ' to TrumpGeneral2'
  884.                 elif os.stat("C:\TrumpGeneral3.txt").st_size == 0:
  885.                     text_file = open("C:\TrumpGeneral3.txt", "w")
  886.                     text_file.write(split9final)
  887.                     text_file.close()
  888.                     print 'Wrote ' + split9final + ' to TrumpGeneral3'
  889.                 elif os.stat("C:\TrumpGeneral4.txt").st_size == 0:
  890.                     text_file = open("C:\TrumpGeneral4.txt", "w")
  891.                     text_file.write(split9final)
  892.                     text_file.close()
  893.                     print 'Wrote ' + split9final + ' to TrumpGeneral4'
  894.                 else:
  895.                     text_file = open("C:\TrumpGeneral5.txt", "w")
  896.                     text_file.write(split9final)
  897.                     text_file.close()
  898.                     print 'Wrote ' + split9final + ' to TrumpGeneral5'
  899.  
  900.         if 'TRUMP GENERAL' in fpage10:
  901.             print 'TG on Page 10'
  902.             split10 = fpage10.split('TRUMP GENERAL', 10)[0] + 'TRUMP GENERAL'
  903.             split10 = split10.replace('{"page":10,"threads":[', '')
  904.  
  905.             compare10 = 1
  906.             while compare10 < 23:
  907.                 def find_between(split10, first, last):
  908.                     try:
  909.                         start = split10.index(first) + len(first)
  910.                         end = split10.index(last, start)
  911.                         return split10[start:end]
  912.                     except ValueError:
  913.                         return ""
  914.  
  915.                 split10compare = find_between(split10, '{"no":', '"last_modified"')
  916.  
  917.                 if 'TRUMP GENERAL' in split10compare:
  918.                     print 'TRUMP GEN RAW ' + split10compare
  919.                     compare10 = 23
  920.                 else:
  921.                     split10 = split10.replace('{"no":"last_modified":', '')
  922.                     split10 = split10.replace(split10compare, '')
  923.                     compare10 += 1
  924.  
  925.  
  926.             def find_between(split10, first, last):
  927.                 try:
  928.                     start = split10.index(first) + len(first)
  929.                     end = split10.index(last, start)
  930.                     return split10[start:end]
  931.                 except ValueError:
  932.                     return ""
  933.  
  934.  
  935.             split10final = find_between(split10, '{"no":', 'TRUMP GENERAL')
  936.             split10final = split10final[0:8]
  937.  
  938.             print 'TG thread id found: ' + split10final
  939.  
  940.             if split10final in open("C:\TrumpGeneral1.txt").read():
  941.                 print 'General already in Slot 1'
  942.             elif split10final in open("C:\TrumpGeneral2.txt").read():
  943.                 print 'General already in Slot 2'
  944.             elif split10final in open("C:\TrumpGeneral3.txt").read():
  945.                 print 'General already in Slot 3'
  946.             elif split10final in open("C:\TrumpGeneral4.txt").read():
  947.                 print 'General already in Slot 4'
  948.             elif split10final in open("C:\TrumpGeneral5.txt").read():
  949.                 print 'General already in Slot 5'
  950.             else:
  951.                 if os.stat("C:\TrumpGeneral1.txt").st_size == 0:
  952.                     text_file = open("C:\TrumpGeneral1.txt", "w")
  953.                     text_file.write(split10final)
  954.                     text_file.close()
  955.                     print 'Wrote ' + split10final + ' to TrumpGeneral1'
  956.                 elif os.stat("C:\TrumpGeneral2.txt").st_size == 0:
  957.                     text_file = open("C:\TrumpGeneral2.txt", "w")
  958.                     text_file.write(split10final)
  959.                     text_file.close()
  960.                     print 'Wrote ' + split10final + ' to TrumpGeneral2'
  961.                 elif os.stat("C:\TrumpGeneral3.txt").st_size == 0:
  962.                     text_file = open("C:\TrumpGeneral3.txt", "w")
  963.                     text_file.write(split10final)
  964.                     text_file.close()
  965.                     print 'Wrote ' + split10final + ' to TrumpGeneral3'
  966.                 elif os.stat("C:\TrumpGeneral4.txt").st_size == 0:
  967.                     text_file = open("C:\TrumpGeneral4.txt", "w")
  968.                     text_file.write(split10final)
  969.                     text_file.close()
  970.                     print 'Wrote ' + split10final + ' to TrumpGeneral4'
  971.                 else:
  972.                     text_file = open("C:\TrumpGeneral5.txt", "w")
  973.                     text_file.write(split10final)
  974.                     text_file.close()
  975.                     print 'Wrote ' + split10final + ' to TrumpGeneral5'
  976.  
  977.     print '..waiting 30 secs and looping..'
  978.     time.sleep(30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement