How do I use this depth first search code to obtain a topological sort?
It appears to me that you are doing too much with the code. For DFS, visit every node following adjacent nodes. As you do that, track the topological ordering.

Here is a straightforward implementation of recursive topological sorting a DAG in Python:

from collections import defaultdict 

class Graph: 

    def __init__(self): 
        self.graph = defaultdict(list) # Node: [adjacency nodes]
        self.nodes = set()

    def add_edge(self, u, v): 
        "Directed edge from vertex u to vertex v"
        self.graph[u].append(v) 
        self.nodes.add(u)
        self.nodes.add(v)

    def mark_as_visited(self, v, visited, topological_ordering): 
        visited[v] = True

        # Recur for all the vertices adjacent to this vertex 
        for current_vertex in self.graph[v]: 
            if visited[current_vertex] == False: 
                self.mark_as_visited(current_vertex, visited, topological_ordering) 

        topological_ordering.insert(0, v) 

    def topological_sort(self): 

        visited = [False]*len(self.nodes) # Mark all the vertices as not visited 
        topological_ordering = [] 

        # Sort starting from all vertices one by one 
        for i in range(len(self.nodes)): 
            if visited[i] == False: 
                self.mark_as_visited(i, visited, topological_ordering) 

        return topological_ordering


# Create a sample DAG
g = Graph() 
g.add_edge(5, 2) 
g.add_edge(5, 0) 
g.add_edge(4, 0) 
g.add_edge(4, 1) 
g.add_edge(2, 3) 
g.add_edge(3, 1) 

# Double check that the algorithm is correct for that DAG
assert g.topological_sort() == [5, 4, 2, 3, 1, 0]