import feedparser
import pickle
import requests

hub = "http://feeds.feedburner.com/ampparit-politiikka" ## collect from ampparit all politics related sites

feed = feedparser.parse( hub )

stored = []

try:
    stored = pickle.load( open( '.history' , 'r' ) )
except:
    pass

stored = []

out = open( 'urls.txt' , 'a')

for item in feed['items']:

    link = item['links'][0]['href']
    _id = link.split('?id=')[1]

    if _id not in stored:

        r = requests.head( link )

        url = r.headers.get('location')

        out.write( _id + ',' +  url + '\n' )

        stored.append( _id )

pickle.dump( stored, open( '.history' , 'w' ) )

import feedparser
import pickle
import requests
import sys

hub = "http://feeds.feedburner.com/ampparit-politiikka" ## collect from ampparit all politics related sites

feed = feedparser.parse( hub )

stored = []

path = sys.argv[0]

try:
    stored = pickle.load( open(  path  + '/.history' , 'r' ) )
except:
    pass

out = open( path + '/urls.txt' , 'a')

for item in feed['items']:

    link = item['links'][0]['href']
    _id = link.split('?id=')[1]

    if _id not in stored:

        r = requests.head( link )

        url = r.headers.get('location')

        out.write( _id + ',' +  url + '\n' )

        stored.append( _id )

pickle.dump( stored, open( path + '/.history' , 'w' ) )

Make path variable working for server side
Make path variable working for server side

  import feedparser
  import pickle
  import requests
+ import sys
  
  hub = "http://feeds.feedburner.com/ampparit-politiikka" ## collect from ampparit all politics related sites
  
  feed = feedparser.parse( hub )
  
  stored = []
  
+ path = sys.argv[0]
+ 
  try:
-     stored = pickle.load( open( '.history' , 'r' ) )
+     stored = pickle.load( open(  path  + '/.history' , 'r' ) )
  except:
      pass
  
- stored = []
- 
- out = open( 'urls.txt' , 'a')
+ out = open( path + '/urls.txt' , 'a')
  
  for item in feed['items']:
  
      link = item['links'][0]['href']
      _id = link.split('?id=')[1]
  
      if _id not in stored:
  
          r = requests.head( link )
  
          url = r.headers.get('location')
  
          out.write( _id + ',' +  url + '\n' )
  
          stored.append( _id )
  
- pickle.dump( stored, open( '.history' , 'w' ) )
+ pickle.dump( stored, open( path + '/.history' , 'w' ) )
  
Make path variable working for server side
## Code Before:
import feedparser
import pickle
import requests

hub = "http://feeds.feedburner.com/ampparit-politiikka" ## collect from ampparit all politics related sites

feed = feedparser.parse( hub )

stored = []

try:
    stored = pickle.load( open( '.history' , 'r' ) )
except:
    pass

stored = []

out = open( 'urls.txt' , 'a')

for item in feed['items']:

    link = item['links'][0]['href']
    _id = link.split('?id=')[1]

    if _id not in stored:

        r = requests.head( link )

        url = r.headers.get('location')

        out.write( _id + ',' +  url + '\n' )

        stored.append( _id )

pickle.dump( stored, open( '.history' , 'w' ) )

## Instruction:
Make path variable working for server side
## Code After:
import feedparser
import pickle
import requests
import sys

hub = "http://feeds.feedburner.com/ampparit-politiikka" ## collect from ampparit all politics related sites

feed = feedparser.parse( hub )

stored = []

path = sys.argv[0]

try:
    stored = pickle.load( open(  path  + '/.history' , 'r' ) )
except:
    pass

out = open( path + '/urls.txt' , 'a')

for item in feed['items']:

    link = item['links'][0]['href']
    _id = link.split('?id=')[1]

    if _id not in stored:

        r = requests.head( link )

        url = r.headers.get('location')

        out.write( _id + ',' +  url + '\n' )

        stored.append( _id )

pickle.dump( stored, open( path + '/.history' , 'w' ) )
