Each of your two "lines" have a start point and an end point. This defines a vector, whose coordinates you can get by subtracting the coordinates of the start point from the coordinates of the end point.
To figure out whether two vectors are going in the same direction, you can look at the oriented angle between them; or better yet, at the cosine of that angle. The cosine will be +1 if they are exactly pointing in the same direction; 0 if they are exactly orthogonal; and -1 if they are pointing in exactly opposing direction. Some intermediary value between -1 and +1 if it's not exact.
See also:
With all that in mind:
def vector_of_segment(start, end):
a, b = start
c, d = end
return (c - a, d - b)
def scalar_product(u, v):
a, b = u
c, d = v
return a * c + b * d
import math
def norm(u):
return math.sqrt(scalar_product(u,u))
# python>=3.8: use math.hypot instead of defining your own norm
def cosine_similarity(u,v):
return scalar_product(u,v) / (norm(u) * norm(v))
def cosine_similarity_of_roads(line1, line2):
u = vector_of_segment(*line1)
v = vector_of_segment(*line2)
return cosine_similarity(u, v)
If you have one of the two awesome libraries numpy and scipy installed, you can also use already-implemented versions of the cosine similarity from these libraries, rather than implementing your own. Refer to the answers to the question I linked above.
Test:
>>> line1 = (13.010815620422363, 6.765378475189209), (-9.916780471801758, 12.464008331298828)
>>> line2 = (-28.914321899414062, 2.4057865142822266),(13.973191261291504, -8.306382179260254)
>>> cosine_similarity_of_roads(line1, line2)
-0.9999993352122917
Your lines are exactly in opposing directions.